[capi-sig] exceptions, the right way

Lee l_armeanu at yahoo.co.nz
Thu Nov 17 11:07:51 CET 2011

Hi All,

I am new to Python C/API, I am trying to follow the official docs, but
I am confused about raising and catching exceptions from an extension.

For the example provided at 

Extending and Embedding the Python Interpreter
2. Defining New Types
2.1.2. Providing finer control over data attributes
eg I don't seem to be able to catch the exceptions raised by the getsetters functions, 
the interpreter will just end up in an ugly crash. Something like:

    del mynoddy.last
except TypeError, e:
    print "Error: ", e

doesn't work. I understand that PyErr_SetString just sets the error and does not raises the exception.

Am I missing something?

I am using Python ver 2.6.6 on Windows.

Any advice is greatly appreciated,

More information about the capi-sig mailing list