I am wrapping a bunch of C++ code using Inline::CPP. When I throw an exception in code called by a wrapped function, the exception doesn't seem to make it through the XS layer up to my catch statement. Perhaps this is actually a C vs C++ problem and not a perl one at all; I'm not sure.
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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.