[C++-sig] Re: Exception translation to python classes

Niall Douglas s_sourceforge at nedprod.com
Tue Sep 23 01:16:26 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 22 Sep 2003 at 12:50, Mike Rovner wrote:

> Niall Douglas wrote:
> 
> > I was wondering if anyone had any experience or could point me to
> > some example code for translating C++ exceptions by using
> > PyErr_SetObject to the Boost.Python wrap of the appropriate C++
> > exception object.
> 
> I'm not quite sure what are you talking about.

Ok, an example then:

FXException is my generic base class for all exceptions. It has 
bindings for Python ie; a FXException is available there too.

I've registered an exception translator for FXException. If what you 
say below is correct, then it merely needs to be:

void FXException_translator(const FXException &e)
{
    PyErr_SetObject(PyExc_RuntimeError, python::object(e));
}

... and all should be good.

If so, then my thanks again. This makes error reporting in python 
much more useful indeed as my exception class provides a stack 
backtrace plus line and file info of the C++ side.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBP2+Cy8EcvDLFGKbPEQKZPQCggXJIiovsg+j3r71fRKJ2FvmCZOEAn2GH
bUFfXBN3Ju7JJVNIyxUOZt04
=BGwZ
-----END PGP SIGNATURE-----




More information about the Cplusplus-sig mailing list