On Thu, Nov 14, 2013 at 12:15 PM, Geoffrey Irving <[email protected]> wrote:
> On Thu, Nov 14, 2013 at 10:06 AM, Matthew Knepley <[email protected]> > wrote: > > On Thu, Nov 14, 2013 at 12:02 PM, Geoffrey Irving <[email protected]> > 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
