:orphan: # PetscCallCXX Checks C++ function calls and if they throw an exception, catch it and then return a PETSc error code ## Synopsis ``` #include void PetscCallCXX(...) noexcept; ``` Not Collective ## Input Parameter - ***__VA_ARGS__ -*** An arbitrary expression ## Notes `PetscCallCXX(...)` is a macro replacement for ```none try { __VA_ARGS__; } catch (const std::exception& e) { return ConvertToPetscErrorCode(e); } ``` Due to the fact that it catches any (reasonable) exception, it is essentially noexcept. If you cannot return a `PetscErrorCode` use `PetscCallCXXAbort()` instead. ## Example Usage ```none void foo(void) { throw std::runtime_error("error"); } void bar() { PetscCallCXX(foo()); // ERROR bar() does not return PetscErrorCode } PetscErrorCode baz() { PetscCallCXX(foo()); // OK PetscCallCXX( bar(); foo(); // OK multiple statements allowed ); } struct bop { bop() { PetscCallCXX(foo()); // ERROR returns PetscErrorCode, cannot be used in constructors } }; // ERROR contains do-while, cannot be used as function-try block PetscErrorCode qux() PetscCallCXX( bar(); baz(); foo(); return 0; ) ``` ## See Also `PetscCallCXXAbort()`, `PetscCallThrow()`, `SETERRQ()`, `PetscCall()`, `SETERRABORT()`, `PetscCallAbort()`, `PetscTraceBackErrorHandler()`, `PetscPushErrorHandler()`, `PetscError()`, `CHKMEMQ` ## Level beginner ## Location include/petscerror.h ## Examples src/snes/tutorials/ex55k.kokkos.cxx
--- [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)