Custom C Exception Subclasses

Ivan Illarionov ivan.illarionov at gmail.com
Wed Dec 24 12:00:36 EST 2008


On Dec 24, 6:42 pm, Ross <rlig... at gmail.com> wrote:
> For a project that I am doing, it would be useful to have an exception
> class that stores some additional data along with the message.
> However, I want to be able to store a couple pointers to C++ classes,
> so I can't just use an exception created with PyExc_NewException.  If
> I were to subclass the built-in Exception type, I would need to have
> access to the PyExc_ExceptionObject, but the headers only give
> PyExc_Exception, the type object.  This seems like a rather
> straightforward task, but I can't seem to find any documentation for
> it.  Does anyone know how to do this?  Thanks!

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.

Ivan



More information about the Python-list mailing list