[capi-sig] exceptions, the right way

Hrvoje Niksic hniksic at xemacs.org
Fri Nov 18 11:17:08 CET 2011

Lee <l_armeanu at yahoo.co.nz> writes:

> 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; }

Does unchanged noddy2.c work correctly for you?  (It seems to contain
the exact check you are quoting.)  Maybe you are compiling noddy2 with a
compiler incompatible to the one used for building Python?

> so, one expects that can do:
> import noddy2
> mynoddy = noddy2.Noddy(number=15)
> mynoddy.first = "a"
> try:
>     del mynoddy.last
> except TypeError, e:
>     print "Error: ", e

This should be possible, yes.

More information about the capi-sig mailing list