[Pyrex] Handling exception when embedding
Franck Pommereau
pommereau at univ-paris12.fr
Mon Nov 19 09:12:48 CET 2007
> But in any case, I don't think exc_info() will work at all with
> an exception caught by a Pyrex try-except statement, because it
> uses information stored in the Python stack frame, and Pyrex
> functions don't have Python stack frames.
>From the description of PyErr_Occurred in the Python/C API reference
manual, I thought that exc_info would get its information from some kind
of global variables:
Exception state is maintained in per-thread storage (this is
equivalent to using global storage in an unthreaded application). A
thread can be in one of two states: an exception has occurred, or
not. The function PyErr_Occurred() can be used to check for this: it
returns a borrowed reference to the exception type object when an
exception has occurred, and NULL otherwise.
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.
>> I get the following message:
>>
>> *** AttributeError: 'NoneType' object has no attribute '__name__' ***
>
> Is that *all* you get? I would have expected a message about an
> unhandled exception in Foo_hello prior to that.
No other message... But this is indeed what I was expecting. (By a
matter of fact, I hoped to be able to emulate __Pyx_WriteUnraisable in
order to get the exception information and store it into a global
variable for the C program, but it calls PyErr_WriteUnraisable instead
of building a string.)
On some variants of my program, I get the message, but on most variants
I don't. I've made so many variants during my exploration that I don't
know exactly which one gives the message and which one doesn't. As I
said in the previous post, sometimes I don't have the warning but more
surprising, my error function fails on a NameError concerning 'sys'.
Thanks for your help,
Franck
More information about the Pyrex
mailing list