[Haskell-cafe] C++ exception (from *.so) catchable by Haskell??
Nick Rudnick
nick.rudnick at gmail.com
Thu Feb 13 20:57:31 UTC 2014
thank you :-)
Injecting the example pointed to by Alexander to my code, e.g.
void myUnexpected () {
std::cerr << "unexpected called\n";
throw 0;
}
...
std::set_unexpected (myUnexpected);
try {
throw runtime_error("OOOPS...");
}
catch (int) { std::cerr << "caught int\n"; }
catch (...) { std::cerr << "caught some other exception type\n"; }
still is the problem that the STDERR message of myUnexpected doesn't appear
– is there anywhere code applying what you told about?
Cheers, Nick
2014-02-13 15:44 GMT+01:00 Brandon Allbery <allbery.b at gmail.com>:
>
> On Thu, Feb 13, 2014 at 6:43 AM, Nick Rudnick <nick.rudnick at gmail.com>wrote:
>
>> 3) To my surprise, every time the output stays the same:
>>
>> terminate called after throwing an instance of 'std::runtime_error'
>> what(): OOOPS.
>>
>
> It's calling terminate which calls exit(), in the C++ runtime. You can't
> catch it at that level.
>
> set_unexpected() may or may not help you since it's not clear that you can
> make it pop back to the FFI call and no further. Maybe you can use
> setjmp()/longjmp() or setcontext() and friends, but I'm betting its
> interaction with C++ is undefined (and in particular C++
> finalizers/destructors don't get called).
>
> Your best bet is to catch the exception in C++, in whatever code you are
> invoking from the (C context) FFI call.
>
> Upshot: there is no global concept of exceptions that applies across all
> languages unless you're using something like JVM or CLR.
>
> --
> brandon s allbery kf8nh sine nomine
> associates
> allbery.b at gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140213/5fb6e001/attachment.html>
More information about the Haskell-Cafe
mailing list