[C++-sig] c++ exception handleing

Stefan Seefeld seefeld at sympatico.ca
Fri Mar 28 23:26:07 CET 2008

Sean Ross-Ross wrote:
> Hi, had coded a c++ algorithm that I have just wrapped with boost,  
> inside the algorithm I have some python callback functions
> when an error is raised in one of the python callbacks, the c++ code  
> (file and line number) is obviously not included in the stack trace.
> Is there an elegant way to provide the user with more information of  
> the exception? perhaps insert the c++ file and line number that the  
> python function was called from?

Certainly. However, the respective Python API isn't (yet) nicely wrapped 
into boost.python, so you'll have to do that manually, i.e. by calling
PyErr_SetObject() yourself. The type and value you set there can be 
anything you like, and so you are free to inject useful information 
about the location the exception happened in. (Of course, you can't 
synthesize a call stack reaching into C++ code, though...)



       ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list