Custom C Exception Subclasses

Gabriel Genellina gagsl-py2 at
Wed Dec 24 20:43:25 CET 2008

En Wed, 24 Dec 2008 15:48:34 -0200, Gabriel Genellina  
<gagsl-py2 at> escribió:

> En Wed, 24 Dec 2008 15:00:36 -0200, Ivan Illarionov  
> <ivan.illarionov at> escribió:
>> When you raise an exception in C++ you can set it to ANY Python object
>> via PyErr_SetObject and that object could store pointers to C++
>> classes.
> Remember that exceptions should inherit from BaseException; although  
> this rule isn't enforced in Python 2.6, 3.0 doesn't allow that.
> It isn't explicitely written in the docs, but I think that  
> PyErr_SetObject won't allow you to pass an object which is not an  
> instance of its first argument.

Correction: you're right, it is OK to pass any other object as the second  
parameter to PyErr_SetObject; it will be used as the argument to the  
exception constructor.

Gabriel Genellina

More information about the Python-list mailing list