Custom C Exception Subclasses

Ivan Illarionov ivan.illarionov at gmail.com
Wed Dec 24 19:07:58 EST 2008


On Dec 24, 10:43 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 24 Dec 2008 15:48:34 -0200, Gabriel Genellina  
> <gagsl-... at yahoo.com.ar> escribió:
>
> > En Wed, 24 Dec 2008 15:00:36 -0200, Ivan Illarionov  
> > <ivan.illario... at gmail.com> 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

Yes, I was talking about the second argument to PyErr_SetObject.

I probably wasn't clear. I meant OP could create normal exception with
PyErr_NewException and use it as a transport for any data, including
C++ wrappers, not only text messages as he probably assumes.

Ivan



More information about the Python-list mailing list