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

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to