Hi Cedric,

> I need to call several functions from Petsc in a C++ code.
I would like to handle manage errors from Petsc with exceptions.

In Petsc's documentation, I found that there exists a macro to do that :
CHKERRXX.

How does it work?

It checks for a nonzero error code and returns from the function immediately if that is the case. Have a look at the implementation here:
http://www.mcs.anl.gov/petsc/petsc-3.5/include/petscerror.h.html

Which kind of exception does it throw in case of failure?
Do you inherit from std::exception?
Is there an exception for each error code?

Neither. You would have to write your own wrapper around it, translating the error codes into exceptions. PETSc cannot use exceptions since it is a C library. Some people also argue against exceptions because they tend to bloat the executable for all the roll-back code.

Best regards,
Karli

Reply via email to