#include <petscerror.h> void PetscCallCXX(expr) noexcept;Not Collective
expr | - An arbitrary expression |
try { expr; } catch (const std::exception& e) { return ConvertToPetscErrorCode(e); }Due to the fact that it catches any (reasonable) exception, it is essentially noexcept.
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 mutliple 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; )