Boost::Python exception translation not working?

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

"Dan" <dan@eloff.info> writes:
What am I doing wrong?
Please post a minimal complete reproducible example (1 c++ file and 1 python file) to the C++ sig (http://www.boost.org/more/mailing_lists.htm#cplussig) and I'll try to help. Also, please let us know which compiler and OS you are using. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

Sorry to trouble you Dave, it was my mistake. I had a couple default arguments for function parameters to the constructor. It seems that Boost::Python doesn't like this ( I was wondering how support for that might have been implemented ) and it causes an exception to be thrown from c++ ( maybe a stack related exception? ) and caught by Boost. Adding multiple overloads solved the issue. Thanks for your time and congradulations on a neat idea that was implemented very cleverly. Cheers, -Dan
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of David Abrahams Sent: Tuesday, August 31, 2004 7:50 PM To: boost@lists.boost.org Subject: [boost] Re: Boost::Python exception translation not working?
"Dan" <dan@eloff.info> writes:
What am I doing wrong?
Please post a minimal complete reproducible example (1 c++ file and 1 python file) to the C++ sig (http://www.boost.org/more/mailing_lists.htm#cplussig) and I'll try to help. Also, please let us know which compiler and OS you are using.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/bo> ost

"Dan" <dan@eloff.info> writes:
Sorry to trouble you Dave, it was my mistake. I had a couple default arguments for function parameters to the constructor. It seems that Boost::Python doesn't like this ( I was wondering how support for that might have been implemented )
I don't understand what constructor you mean.
and it causes an exception to be thrown from c++ ( maybe a stack related exception? )
I don't know enough about your problem to say. Again I request you post a minimal complete example to the C++ sig.
and caught by Boost. Adding multiple overloads solved the issue. Thanks for your time and congradulations on a neat idea that was implemented very cleverly.
Not so very cleverly, if you had problems :(
Cheers, -Dan
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com

I thought the problem was that I had a constructor with optional arguments. I got rid of that and it seemed to work. MySQL( const char * host = NULL ) I spoke too soon though. The real problem was something that I've had before and drives me crazy every time I encounter it. Ironically if I tried the above, it would probably work now. I simply forgot to call mysql_init(). I really do hate these C APIs. That took me a frustrating 6 hours to track down. Boost::Python did not have any problems, and has been a very pleasant experience to work with. Most often things work they way I would expect them to. Sorry again for the confusion. -Dan
participants (2)
-
Dan
-
David Abrahams