[Haskell-cafe] C++ exception (from *.so) catchable by Haskell??

Brandon Allbery allbery.b at gmail.com
Thu Feb 13 14:44:06 UTC 2014

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/41e02c59/attachment.html>

More information about the Haskell-Cafe mailing list