[C++-sig] question on boost.python exception mechanisms

Holger Joukl Holger.Joukl at LBBW.de
Wed Apr 10 13:48:14 CEST 2013


Hi,

"Cplusplus-sig" <cplusplus-sig-bounces+holger.joukl=lbbw.de at python.org>
wrote on 09.04.2013 03:04:33:

> From: "Niall Douglas" <s_sourceforge at nedprod.com>

> On 8 Apr 2013 at 14:11, Holger Joukl wrote:
>
> > > I have found a couple of references.
> > > http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (see
static-libgcc)
> > > http://gcc.gnu.org/wiki/Visibility
> >
> > Thanks, I'll need to look into these.
>
> I wrote the second one. Really not sure how that helps you.

At the very least I'll definitely learn something :-)

> Look into capturing the exception before it enters the C code using
> std::exception_ptr, and then rethrowing it on reentry to C++.

In a similar approach I'm trying out I currently catch
bp::error_already_set before entering
C Code and on reentry to C++ call bp::throw_error_already_set() iff
PyErr_Occurred().
So I basically make use of Python's global-per-thread exception indicator
to "suppress"
the exception for the C code and detect the need to re-raise before
returning from C++
to Python.

I guess that will work just fine unless some non-Python related exception
creeps
in, either raised from within Boost.Python or in my custom code.

> If you don't have C++11 in your C++, Boost provides an okay partial
> implementation of C++11 exception support.

I'll look into this. This would then mean instrumenting some object with a
place
to store the caught exception to re-raise upon reentry from C to C++.
I take it this would then do much the same as my approach sketched above
but
"safer and sounder".

Thanks,
Holger

Landesbank Baden-Wuerttemberg
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
HRA 12704
Amtsgericht Stuttgart



More information about the Cplusplus-sig mailing list