Custom C Exception Subclasses

Ivan Illarionov ivan.illarionov at
Wed Dec 24 18:00:36 CET 2008

On Dec 24, 6:42 pm, Ross <rlig... at> 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++


More information about the Python-list mailing list