sfink has asked for the wisdom of the Perl Monks concerning the following question:
In more detail, I have a C++ try block containing a call to eval_sv, which calls a bunch of functions including both functions in libperl.so (which are compiled as C) and wrapped XS functions (which are compiled as C++). One of those XS functions calls my C++ function, which throws an exception. I get an immediate abort, rather than having the exception caught by my catch(...) clause.
I could change every wrapper function to do a try {} block around everything it does, in order to convert the C++ exception to a Perl exception, but I'd love to avoid the extra work if possible.
Update: It turned out to be a C vs C++ thing, more or less. The problem is that to unwind the stack on an exception, C++ leaves a trail of breadcrumbs all the way up the stack in order to call the appropriate destructors etc. C does not. gcc controls this with the -fexceptions, which is enabled by default for C++ and disabled for C. So, the easiest solution is to recompile perl with the flag added -- I have tried it, and it works great!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to propagate C++ exceptions through XS
by knexus (Hermit) on Mar 11, 2004 at 20:41 UTC |