PyErr_SetString() != raise ?

Paul Simmonds psimmo60 at hotmail.com
Tue Jul 15 13:37:44 EDT 2003


David Eger <eger at cc.gatech.edu> wrote in message news:<bevkb3$mg8$1 at solaria.cc.gatech.edu>...
> When I use PyErr_SetString() in an extension, python just keeps on
> chugging instead of acting as though a Python exception had been
> 'raise'd.  Why is this, and do I really have to write the Python code
> to raise an exception manually after I've used PyErr_SetString()?
> 
>     if (nextEl == NULL) {
>       PyErr_SetString(PyExc_StopIteration, "Array index out of bounds");
>       return NULL;
>       }
> 
> in my iterator extension, but when I use my extension, I get an infinite loop:
<snipped>
> (and so on, and so on...)  The thing is, even though I *set* the
> exception with PyErr_SetString, to the interpreter, it doesn't get
> raised.  Am I just misinterpretting how PyErr_SetString is supposed 
> to work?
> 
> -David
Hi,

This part should work fine. Try looking back through the function
calls, layer by layer, making sure each function in turn tests for a
NULL return, and propagates it back to the interpreter. Without a
little more code it's tough to say exactly what's wrong.

The NULL return tells the interpreter that an exception has occurred.
PyErr_SetString just sets the traceback message.
 
HTH,
Paul




More information about the Python-list mailing list