[C++-sig] How to create a custom exception derived from Exception
Jim Bosch
talljimbo at gmail.com
Tue Jul 31 12:58:07 CEST 2012
On 07/31/2012 06:14 PM, Glenn Ramsey wrote:
>
> Using boost::python how can I create an a custom exception that is
> derived from Python's Exception? The functionality I would like to get
> by doing this is to provide additional methods for the catching code to
> retrieve information from the exception.
>
The approach I've taken in the past (sorry, don't have an example right
now) is to raise a true Python exception (from PyErr_NewException), and
attach your Boost.Python-wrapped C++ exception to it as an instance
variable. Then put a __getattr__ in the true Python exception that
forwards to the Boost.Python object it holds.
I can try to reconstruct more details if needed, but hopefully that's
enough to get you started.
Jim
More information about the Cplusplus-sig
mailing list