[C++-sig] Ping: Howto expose exception classes using boost.python?

Ryan Gallagher ryan.gallagher at gmail.com
Thu May 18 02:34:11 CEST 2006


Alex Mohr <amohr <at> pixar.com> writes:
> The way I solved it was to actually implement an exception class in 
> python (that derived from RuntimeError) and then call into my wrapped 
> module, passing that class object.

Hi Alex,

Yeah, I think that I mentioned in an earlier post that this was the 
way I solved it too.  It works, just not quite as simple and pretty, and
requires someone to learn a bit of Python/C API.  

Perhaps this is a good solution for someone to put on the boost wiki.

> [snip]
> It would be lovely if boost python let you create extensions classes 
> that derived from python classes, but I'm not sure what this would entail.

I agree but am also not sure of what it would entail.  I had been thinking 
the same thing when I first started looking into this.

For exceptions, though, it appears that using PyErr_NewException is the 
preferred method by the Python/C API.  Although, I would think that it
should still be possible to set up a new exception class without using this
but deriving from an Exception decendent and setting up the dictionary properly.

Thanks for the reply, it sounds like we've gone down similar tracks with
all this.  That's encouraging.  Cheers,

-Ryan





More information about the Cplusplus-sig mailing list