[python] create a custom exception
Is it possible to create a C++ to python exception translator that raises a custom python exception? I know you can use register_exception_translator to translate from a c++ exception to a standard python exception, but is it possible to raise a user-defined exception? Regards, Colin
boost.users@cgrealy.mailcan.com writes:
Is it possible to create a C++ to python exception translator that raises a custom python exception?
I know you can use register_exception_translator to translate from a c++ exception to a standard python exception, but is it possible to raise a user-defined exception?
I think a translator something like this might work: namespace python = boost::python; void translate(SomeCplusplusException const& x) { static python::object py_exception_class( python::exec( "class MyPythonException: pass; MyPythonException") ); PyErrSetString(py_exception_class.ptr(), "My message"); } BTW, it's usually better to ask Boost.Python questions on the C++-sig: http://www.boost.org/more/mailing_lists.htm#cplussig HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
boost.users@cgrealy.mailcan.com
-
David Abrahams