Getting error message/trace over the C API

Duncan Booth duncan.booth at invalid.invalid
Tue Oct 16 14:55:22 EDT 2007


Sami Vaisanen <ensiferum_ at hotmail.com> wrote:

> Hello group,
>  
> I'm writing a C++ based application that embeds the python engine. Now I
> have a problem regarding exception/error information. Is there a way to
> get the exception message and possibly the traceback into a string for
> example? I've been eyeballing the PyErr_ module and it seems fairly
> limited. In other words PyErr_Print() calls the right functions for
> getting the exception information but unfortunately it is hardwired to
> print this data directly into sys.stderr, and for an embedded application
> this is completely inappropriate. 
>  
>  
> Please advice how to do this.
> 
All you have to do is call whatever functions you would call from Python. 
e.g. from C you need to import traceback, then call getattr to get the 
appropriate function (e.g. format_exc or format_exception), then just call 
it.



More information about the Python-list mailing list