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

Matthew Knepley knepley at gmail.com
Thu Nov 14 12:22:31 CST 2013


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

> On Thu, Nov 14, 2013 at 10:06 AM, Matthew Knepley <knepley at gmail.com>
> wrote:
> > 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
>
> Thanks, that'll work.  I guess my hope for a magical solution where I
> didn't have to call the check macro blinded me to the obvious "pass
> PETSC_ERROR_IN_CXX" myself path.
>
> Minor curiosity: why does the _MSG version not use PetscUnlikely?


I think I wrote the other one later and did not update.

   Matt


>
> 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/31191d6a/attachment.html>


More information about the petsc-users mailing list