[petsc-dev] CHKERRXX() PetscErrorCxx, PetscTraceBackErrorHandlerCxx()

Barry Smith bsmith at mcs.anl.gov
Tue May 11 18:56:43 CDT 2010



   I've been trying to understand the use of CHKERRXX() PetscErrorCxx(), PetscTraceBackErrorHandlerCxx() and think it is messed up.

   Assumptions 
1) real PETSc c++ code (that is PETSc code that uses C++ constructs, has .cxx extensions) can call PETSc c code (the normal old PETSc source) 
2) PETSc c code cannot call PETSc c++ code
3) PETSc c++ code uses C++ exceptions for error handling, NOT return values.
are these correct?

   Thus when PETSc c++ code calls PETSc c code it needs to translate any PETSc error return codes to C++ exceptions.  This is currently done by CHKERRXX() being a macro to PetscErrorCxx() that then calls PetscTraceBackErrorHandlerCxx() that actually generates the exception.  But PetscErrorCxx() is not really the same thing as calling PetscError and PetscTraceBackErrorHandlerCxx() is not really a C++ version of PetscTraceBackErrorHandler(). Plus PetscTraceBackErrorHandlerCxx() is not an error handler because it cannot be set with PetscPushErrorHandler().

   I have started to reorganize this. 

 Turned PetscTraceBackErrorHandlerCxx() into a regular handler that can be pushed. Put the stream it uses into the handler context. 
Removed PetscErrorCxx()
Added to PetscError() to automatically generate an exception if the caller is a C++ routine; as indicated by the PetscErrorType flag that is passed in.
Changed CHKERRXX() to simply call PetscError() with the appropriate PetscErrorType of PETSC_ERROR_IN_CXX
Not yet tested the PetscTraceBackErrorHandlerCxx() 

   Barry




More information about the petsc-dev mailing list