Boost logo

Boost :

From: Dan (dan_at_[hidden])
Date: 2004-08-31 17:39:33


I attempted a simple exception translation that was almost an exact copy
of the examples in the docs.

struct MySQLException : public std::exception
{
        MySQLException( const char * what = "MySQL Exception" ) :
std::exception( what ) {}
};

And then in a class's default constructor I throw this exception.

I tried exposing it as both a function and a functor:

void mysql_translate( MySQLException& e )
{
        PyErr_SetString( PyExc_RuntimeError, e.what() );
}

BOOST_PYTHON_MODULE(pymysql)
{
        // regular expression translation

        py::register_exception_translator< MySQLException >(
&mysql_translate );
}

And...

struct mysql_translate
{
        void operator ()( const MySQLException& e ) const
        {
                PyErr_SetString( PyExc_RuntimeError, e.what() );
        }
};

BOOST_PYTHON_MODULE(pymysql)
{
        // regular expression translation

        py::register_exception_translator< MySQLException >(
mysql_translate() );
}

Both had the same result when I created the exported object.
"RuntimeError: unidentifiable C++ exception".

What am I doing wrong?

Thanks,
-Dan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk