<div dir="ltr"><div><div><div><div><br></div>Thanks Peter for that informative answer.<br><br></div>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.<br>

<br></div>How this is done is at the ABI level, but the Itanium C++ ABI, which is the one used for x86-* does this.<br><br><a href="http://mentorembedded.github.io/cxx-abi/abi-eh.html">http://mentorembedded.github.io/cxx-abi/abi-eh.html</a><br>

<br></div><div>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.<br>

<br></div><div><div>Alexander<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 12:38 AM, Peter Simons <span dir="ltr"><<a href="mailto:simons@cryp.to" target="_blank">simons@cryp.to</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nick,<br>
<br>
please note that the handler set by std::unexpected() fires only if a<br>
function violates its exception specification, i.e. the function<br>
<br>
  void foobar() throw() { throw 0; }<br>
<br>
would trigger std::unexpected_handler(), but<br>
<br>
  void foobar() { throw 0; }<br>
<br>
does not, because there is no "unexpected" exception. Uncaught exceptions,<br>
on the other hand, trigger the function std::terminate(), which by default<br>
translates to std::abort().<br>
<br>
Brandon Allbery pointed this out before, but it's probably worth<br>
repeating: there is no way to catch (or throw) a C++ exception in Haskell.<br>
The internal details of C++ exception handling are "implementation<br>
defined". There is no standard that defines how to implement exceptions,<br>
which means that you cannot even mix code from different C++ compilers if<br>
you want to handle exceptions. Mixing in Haskell code is probably next to<br>
impossible.<br>
<br>
Take care,<br>
Peter<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>