Boost logo

Boost :

Subject: Re: [boost] [Python] Improved exception handling for Python embedding
From: Stefan Seefeld (stefan_at_[hidden])
Date: 2014-08-01 09:56:18

Hi Michael,

[I believe this mail should best be sent to the c++-sig_at_[hidden] ML,
so I'm cross-posting there for follow-up.]

On 2014-08-01 07:40, Michael Koenig wrote:
> Hey guys!
> Boost.Python throws boost::python::error_already_set exceptions
> whenever calls to embedding functions such as boost::python::import()
> or boost::python::exec() fail.


> This exception is just an empty class. It does not provide any
> information on the error which occurred on the Python side. It is not
> even a standard exception in the C++ sense.
> As a result, debugging problems with embedded Python code or even the
> Python environment (available packages etc.) with the current
> exception handling mechanism is difficult.

I have long wanted to improve the handling of Python exceptions in
Boost.Python, and wrapping the CPython exception handling API seems a
good start.

> So far, in our company we wrap most Boost.Python functions with custom
> exception handling code.
> In our exception handling code, we basically work the CPython API to
> extract details of Python exceptions such as
> * Exception types,
> * Error messages, and
> * Stack traces.

Right, that seems natural and convenient. However, I'm not sure this
addresses any of the points you raise above. Notably,
does your API allow you to catch specific (Python) exceptions ? In other
words, do you provide a C++ class hierarchy of exceptions reflecting the
Python exception class hierarchy ? How do these exception types relate
to the error_already_set class ?

> We want to put this part of our embedding library back into the
> Boost.Python project. At the EuroPython 2014 conference in Berlin, I
> had a few discussions with Reinhard Wobst, Austin Bingham, and others,
> and the current exception handling mechanism was perceived an
> impediment on the usability of Boost.Python.
> I am most grateful for feedback of seasoned Boost contributors (and
> users) whether my proposal is of sufficient interest and how best to
> pursue it.

I'm very much interested in seeing the API changes you propose, either
in form of a API document or a patch.


      ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at, gregod at, cpdaniel at, john at