Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-02-01 21:09:23


boost.users_at_[hidden] 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net