Custom C Exception Subclasses

Ross rlight2 at gmail.com
Wed Dec 24 13:24:42 EST 2008


On Dec 24, 9:24 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> In fact you can, you could store those pointers as attributes of the
> exception object, using a PyCObject.

Excellent.  I was not aware of the PyCObject type.

> Accessing those attributes isn't as easy as doing exc->field, but I think
> it's easy enough. Inheriting from some exception type requires you to
> define the type structure and fill it right, and IMHO is a lot harder.
>
> Perhaps there is a misunderstanding here. To subclass a type, you need the
> type, not an instance of such type.

Ah yes, I probably should have been more clear.  In the docs about
subclassing, they use a PyListObject as the first field of the Shoddy
struct so that the fields are filled in correctly.

Now, how would I go about adding methods to a custom exception object?



More information about the Python-list mailing list