On Thu, Feb 13, 2014 at 6:43 AM, Nick Rudnick <nick.rudnick@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@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net