Raising exceptions during call back

Martin von Loewis loewis at informatik.hu-berlin.de
Mon May 29 11:53:56 EDT 2000


"Makhno" <mak at imakhno.freeserve.co.uk> writes:

> def mysub():
>     t=(1,2)
>     print t[3] #error!
> 
> EnterCallBack()
> 
> If I call print_stack() from the extension module, I only get trace
> information up to the EnterCallBack() call, it says nothing about where an
> error occured inside mysub(), which I'm sure you can imagine would make it
> very difficult to write code for.

When you get an exception in a C module, immediately release all
resources, and return NULL as well. That way, the entire stack will
wind up, and Python will print the full traceback.

Alternatively, if you want to print the backtrace in the module, use
PyErr_Print().

Regards,
Martin




More information about the Python-list mailing list