[C++-sig] Python exceptions

Jonathan Brandmeyer jbrandmeyer at earthlink.net
Sat Jan 8 01:35:27 CET 2005


On Fri, 2005-01-07 at 16:12 -0800, Garrick Meeker wrote:
> I'm porting some old code to boost.  I have a function that returns a 
> PyObject* and if an error occurs it calls 
> PyErr_SetString(PyExc_AttributeError, "...") and returns NULL.  No C++ 
> exceptions are involved.  With boost, however, the NULL is converted to 
> None.
> 
> How can I generate an AttributeError exception?  All I see from the docs 
> is that I could define a new class, call 
> register_exception_translator(), and throw this class.  Since I'm not 
> dealing with existing exception classes, is there a simpler, built-in 
> way?  Something like:
> 
> throw boost::python::exception(PyExc_AttributeError, "error string");
> 


See: http://www.boost.org/libs/python/doc/v2/errors.htm

-Jonathan




More information about the Cplusplus-sig mailing list