:orphan:
# PetscFunctionReturn
Last executable line of each PETSc function used for error handling. Replaces `return()`. 
## Synopsis
```
#include <petscerror.h>
void PetscFunctionReturn(...)
```
Not Collective; No Fortran Support




## Notes
This routine is a macro, so while it does not "return" anything itself, it does return from
the function in the literal sense.

Usually the return value is the integer literal `0` (for example in any function returning
`PetscErrorCode`), however it is possible to return any arbitrary type. The arguments of
this macro are placed before the `return` statement as-is.

Any routine which returns via `PetscFunctionReturn()` must begin with a corresponding
`PetscFunctionBegin`.

For routines which return `void` use `PetscFunctionReturnVoid()` instead.


## Example Usage
```none
   PetscErrorCode foo(int *x)
   {
     PetscFunctionBegin; // don't forget the begin!
     *x = 10;
     PetscFunctionReturn(PETSC_SUCCESS);
   }
```


May return any arbitrary type:
```none
  struct Foo
  {
    int x;
  };

  struct Foo make_foo(int value)
  {
    struct Foo f;

    PetscFunctionBegin;
    f.x = value;
    PetscFunctionReturn(f);
  }
```



## See Also
 `PetscFunctionBegin`, `PetscFunctionBeginUser`, `PetscFunctionReturnVoid()`,
`PetscStackPopNoCheck()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscerror.h.html#PetscFunctionReturn">include/petscerror.h</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/dt/dualspace/impls/lagrange/tutorials/ex2.c.html">src/dm/dt/dualspace/impls/lagrange/tutorials/ex2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/field/tutorials/ex1.c.html">src/dm/field/tutorials/ex1.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex10.c.html">src/dm/impls/plex/tutorials/ex10.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex11.c.html">src/dm/impls/plex/tutorials/ex11.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex5.c.html">src/dm/impls/plex/tutorials/ex5.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex6.c.html">src/dm/impls/plex/tutorials/ex6.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex7.c.html">src/dm/impls/plex/tutorials/ex7.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex8.c.html">src/dm/impls/plex/tutorials/ex8.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/tutorials/ex9.c.html">src/dm/impls/plex/tutorials/ex9.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/tutorials/ex2.c.html">src/dm/impls/stag/tutorials/ex2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/tutorials/ex3.c.html">src/dm/impls/stag/tutorials/ex3.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscerror.h)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
