[Pyrex] Handling exception when embedding

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Nov 19 11:27:23 CET 2007


Franck Pommereau wrote:
> From the description of PyErr_Occurred
> 
>    Exception state is maintained in per-thread storage (this is
>    equivalent to using global storage in an unthreaded application).

Yes, but PyErr_Occurred is checking the variables that hold
the exception *before* it's been caught, whereas sys.exc_info
retrieves the exception *after* it's been caught. Since Pyrex
stores the caught exception in private variables of its own,
there's no way sys.exc_info could find it.

> I hoped to be able to emulate __Pyx_WriteUnraisable in
> order to get the exception information

To get info about an exception that hasn't been caught yet,
you would have to call PyErr_Fetch. But you'll find it
difficult to do that in Pyrex, because as soon as an
exception is available for PyErr_Fetch to fetch, Pyrex
will bypass all your code propagating the exception.

> So, If this is not the case, I guess I have to encapsulate all my
> wrappers into a try/catch in order to get what I want.

You'll need at least one try-except somewhere, either in
Pyrex or Python.

--
Greg



More information about the Pyrex mailing list