[C++-sig] Letting exception through

David Abrahams dave at boost-consulting.com
Thu Jul 7 21:09:38 CEST 2005


Nikolay Mladenov <nickm at sitius.com> writes:

> Hi,
>
> I have a python interpreter running as a plugin to at third party
> software, and I use boost.python to expose some functionality of
> this software to python.

Let's see:

  3rd-party app                           <----------+
    calls Python interpreter in your plugin          |
      which calls a Boost.Python extension module ---+
         (which calls back into the 3rd party app to expose its
          functionality)

??
         
> I am having the following problem. At times they (the third party
> software) throw std::exception which they apparently expect to
> catch,


> because when boost.python catches it on the boundary between
> python and C++, the software crashes.

You conclude that they expect to catch the exception because the
application crashes at the moment that Boost.Python catches the
exception?  That conclusion seems highly suspect.  In general any
intermediate library should be able to catch an exception and rethrow
it without the 3rd party app being any the wiser, so if the crash is
really happening at the catch point, something else is wrong.

> So my question is is there a way to have certain exceptions flow
> through the boost.python boundary?

Maybe you could do it by registering a special exception
translator... 

... but don't do it; it would be very, very wrong!  It will 
certainly crash Python if a C++ exception propagates into it.  What
you need to do, if my picture is right, is translate the exception
into something that Python can propagate (e.g. by serializing it), and
then ressurect the exception (e.g. by deserializing it) in your
plugin, and throw that.

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




More information about the Cplusplus-sig mailing list