C-API PyObject_Call

Stefan Behnel stefan_ml at behnel.de
Wed Mar 17 02:46:20 EDT 2010


moerchendiser2k3, 16.03.2010 19:25:
> Hi, currently I am not at home, I will post some stuff when I am back.
> Just the note: I throw an exception with the C API.
>
> Looks like that
>
>
> PyObject *result = PyObject_Call(my_isntance, "", NULL);
> if(result==NULL)
> {
>      PyErr_Print(); //when this happens, the traceback is correct with
> information about the file/line
>      return;
> }
>
> if(!PyXYZ_Check(result))
> {
>      PyErr_SetString(PyExc_TypeError, "Wrong type, ....");
>      PyErr_Print(); //missing information of the file/line.
>      return;
> }
>
> Well, I expect, that there are no information about the line/file, so
> I know something is missing, but what is missing?

Two solutions here:

1) put the line number information into the message string when you raise 
the exception

2) use Cython instead of plain C, as Cython will automatically generate 
readable stack traces for you, also for non-Python functions.

Stefan




More information about the Python-list mailing list