[petsc-users] proper way to make petsc throw exceptions on errors?

Matthew Knepley knepley at gmail.com
Thu Nov 14 12:06:23 CST 2013


On Thu, Nov 14, 2013 at 12:02 PM, Geoffrey Irving <irving at naml.us> wrote:

> Is there a safe way to make petsc throw exceptions from C++ code,
> without interfering with the same passage from errors through C code?
> The existence of PETSC_ERROR_IN_CXX and PetscPushErrorHandler seems
> promising?  Could I push a C++ error handler at the top of a C++
> function and pop it and the end, for example?
>

PyLith uses:

#define PYLITH_CHECK_ERROR(err) do {if (PetscUnlikely(err))
{PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,err,PETSC_ERROR_IN_CXX,0);}}
while(0)

#define PYLITH_CHECK_ERROR_MSG(err, msg) \
  if (err) { \

PetscError(PETSC_COMM_SELF,__LINE__,__FUNCT__,__FILE__,err,PETSC_ERROR_IN_CXX,
0, " "); \
    throw std::runtime_error(msg); }

   Matt


> Note that "no" is a fine answer. :)  I only want to do this if there's
> a way to do it cleanly.  The alternative is wrapping a CHECK macro
> around all my calls to petsc from C++, which is far superior to a
> fancy but broken solution.
>
> Thanks,
> Geoffrey
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131114/804661f7/attachment.html>


More information about the petsc-users mailing list