[C++-sig] Re: Custom exceptions

David Abrahams dave at boost-consulting.com
Sun Jun 1 21:13:38 CEST 2003


Gavin Doughtie <gavin at doughtie.com> writes:

> Gavin Doughtie wrote:
>> So, let's say I want to register a custom exception which python
>> code can catch, thusly:
>> try:
>>     doSomething()
>> except mymodule.MyException e:
>>     print e
>> Is there anything in boost python that makes setting this up easy?
>> I've got a working exception translator and everything, but I don't
>> see anything equivalent to putting
>> "PyErr_NewException("mymodule.MyException", NULL, NULL)" into the
>> system dictionary during module initialization.
>> Or am I just working too hard again?

Nope, thatt didn't make it into any release yet, though I've been
meaning to do it for some time.

> Just a note -- I did in fact realize that this is what the "scope"
> function is for. 

scope is a class; did you look at
http://www.boost.org/libs/python/doc/v2/scope.html?

> Now I'm writing a templated exception generator class for my custom
> exceptions. Once that's working (i.e. once I fix my boost::bind
> calls to not crash gcc 2.96) I'll post it.

Wonderful!  I'd love to have something like that in the library!

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list