[C++-sig] boost::python embedding error handling
Jeffrey Holle
jeff.holle at verizon.net
Thu Jul 1 05:36:21 CEST 2004
The good news is that now I can get useful error messages from
boost::python, I'm more than willing to use it. Its a keeper!
I would like to provide some critism of the
boost::python::error_already_set exceptions.
1. It doesn't inherit from std::exception.
2. It provides no information.
On the other hand, its concept of obtaining error information from the
python interpreter is soundly a good idea. Its just isn't finished.
I've written what I would consider a replacement for it and attached it.
Note that the code it its constuctor is pretty much what Chad Austin
contributed to this news group. Thanks.
To use it, I will need to place a try clause around all boost::python
embedding code with the following catch clause:
catch (error_already_set&) {
throw python_error();
}
I consider this acceptable, but it would be better to not need it.
In critism of python_error:
1. It inherits from std::runtime_error. It can be argued, I think,
that it should be std::exception instead. Becaue std::runtime_error
doesn't provide protected access to its string attribute, I've had to
provide one in python_error. This means there is need for a "what"
method implementation and that runtime_error's attribute is wasted bagage.
2. It arguably does too much in its constructor. This is a convenence
issue for me. Constructed at a lower level, it could easily be changed.
3. Chad's code assumes that the python objects returned from
PyErr_Fetch are strings. I do not know if this assumption is safe.
I've seen code on the web that does not make it.
4. As Chad indicated, his code presently doesn't handle the traceback
info. I plan to add this to python_error as a seperate attribute and
accessor, eventually ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python_error.cpp
Type: text/x-c++
Size: 832 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20040630/f42c1c97/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python_error.h
Type: text/x-c-header
Size: 428 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20040630/f42c1c97/attachment-0001.bin>
More information about the Cplusplus-sig
mailing list