[C++-sig] Re: throw_error_already_set()
David Abrahams
dave at boost-consulting.com
Wed Dec 17 20:51:12 CET 2003
"Niall Douglas" <s_sourceforge at nedprod.com> writes:
> Now I have my custom exception which interrogates python and builds a
> very useful C++ exception replete with python traceback, I'd like
> this to be generated whenever there's a python exception raised.
>
> Unfortunately, the C++ exception error_already_set appears to be
> thrown not only for python exceptions but also for internal BPL
> errors
Specifics, please.
I think you're misinterpreting things. Internal errors in BPL are
always handled with assert(), and never with exceptions.
> I'd far prefer BPL to keep throwing error_already_set when it
> can't match parameter types etc. and throw my exception when it's
> just a plain python problem. OTOH, BPL seems to set the python error
> state when it throws error_already_set so maybe this is okay.
OK. Sorry, is there a problem or not?
> Is it possible to modify BPL to do this
I don't think so. Well, OK, we could provide a hookable error
handler. I'd worry how it'd interact with threads, though.
Why don't you just look at the python error state at the catch
point?
> or am I relegated to wrapping every BPL call with a
> try...catch(error_already_set &)?
I think you need to re-evaluate your EH strategy. You must be
embedding Python. You should handle Boost.Python errors in the same
place where you handle other exceptions in your program.
> I did notice there only appears to be one place where
> error_already_set is caught within BPL - therefore couldn't I
> literally just do a find & replace (or better, a #define
> throw_error_already_set FXPython::int_throwPythonException() so I
> don't have problems with merging new releases)
No comment. Modify your private copy of the Boost.Python sources at
your peril (or not).
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list