faqts : Computers : Programming : Languages : Python : Extension Programming

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 10 people (70%) answered Yes
Recently 5 of 8 people (63%) answered Yes

Entry

How do I check and retrieve the error conditions & message of script executed via the Python/C API (without using PyErr_Print)

Oct 29th, 2000 23:26
unknown unknown, Kostas Karanikolas, Alex Martelli


See Section 4, "Exception Handling", in the Python/C API
Reference Manual.  PyErr_Occurred() returns a borrowed-
reference pointer to the latext exception-type PyObject if
any is pending, NULL if no error is pending; to check
whether the exception is one you want to handle, pass
this non-NULL pointer as the first argument to function
PyErr_GivenExceptionMatches, second argument being
the exception-type or class you want to handle -- it will
return non-0 if matching.
For finer control, you can call PyErr_Fetch, with three
PyObject** arguments, for type, value, and traceback
objects -- if no error is pending, each pointed-to pointer
will be set to 0; else, at least the first (to type-object)
will be non-0 (a reference will have be added to objects
returned in this way).  What you mean by "message"
is probably what you get by PyObject_Str on the value
object pointer (if non-0).