
Thanks Peter for that informative answer.
One unmentioned fact is that the exception mechanism in C++ is designed to
allow for implementations to have zero runtime cost. Basically exception
handlers can be found by matching the stack frames with tables, and
registers can be populated using basically debug info.
How this is done is at the ABI level, but the Itanium C++ ABI, which is the
one used for x86-* does this.
http://mentorembedded.github.io/cxx-abi/abi-eh.html
An interesting nugget I learned today reading up on the ABI is that the ABI
actually supports common lisp conditions, that is, restarting or continuing
a computation that is in an exceptional state is supported by the ABI, but
not by C++. I don't know of any language that supports zero-overhead
exceptions and conditions, but the support is already standardized. It
isn't unthinkable that some C++ implementation would have extensions to
hook into the exception handling mechanism before stack-unwinding happens.
Alexander
On Fri, Feb 14, 2014 at 12:38 AM, Peter Simons
Hi Nick,
please note that the handler set by std::unexpected() fires only if a function violates its exception specification, i.e. the function
void foobar() throw() { throw 0; }
would trigger std::unexpected_handler(), but
void foobar() { throw 0; }
does not, because there is no "unexpected" exception. Uncaught exceptions, on the other hand, trigger the function std::terminate(), which by default translates to std::abort().
Brandon Allbery pointed this out before, but it's probably worth repeating: there is no way to catch (or throw) a C++ exception in Haskell. The internal details of C++ exception handling are "implementation defined". There is no standard that defines how to implement exceptions, which means that you cannot even mix code from different C++ compilers if you want to handle exceptions. Mixing in Haskell code is probably next to impossible.
Take care, Peter
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe