[capi-sig] exceptions, the right way

Lee l_armeanu at yahoo.co.nz
Thu Nov 17 20:33:30 CET 2011

Thanks Marc-Andre,
> If not, you simply pass on

> the NULL/-1 return value to the higher level function in your call
> stack.

This is exactly my problem. What I am trying to do (and the example seems to show) is:
- define an new type.
- define getsetters functions.
- say, if one want to delete an attribute, one writes in the setter function:

if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete the last attribute"); return -1; }

so, one expects that can do:

import noddy2
mynoddy = noddy2.Noddy(number=15)
mynoddy.first = "a"
    del mynoddy.last
except TypeError, e:
    print "Error: ", e

(passing the PyExc_TypeError to the interpreter). In my situation try/except is ignored and 
the interpreter crushes.
Am I missing something?


More information about the capi-sig mailing list