<div dir="ltr">Forcing the exception to WHNF doesn't do anything to resolve any of the other bottom values you might attempt to force inside your exception handler contained inside the thrown exception value. I think that the current behavior makes sense as it exists now. I'd prefer not making throwIO more magical. The user of throwIO throwing a potentially undefined exception value should take care to evaluate the exception before throwing it if that is a concern.<div><br></div><div>Did this happen in some code somewhere that you discovered? It might be more compelling if we could see how this came up it some otherwise reasonable code.<br><div><br></div><div>Regards,</div><div>Eric Mertens</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Feb 27, 2017 at 12:42 PM David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It's possible for code to throw an exception that itself throws an<br class="gmail_msg">
imprecise exception. Such an exception is a bit tricky to catch. For<br class="gmail_msg">
example:<br class="gmail_msg">
<br class="gmail_msg">
import Control.Exception<br class="gmail_msg">
<br class="gmail_msg">
strange = throwIO (undefined :: SomeException) `catch` \ex -><br class="gmail_msg">
  case () of<br class="gmail_msg">
    _ | Just _ <- (fromException ex :: Maybe IOError) -> print "IOError"<br class="gmail_msg">
      | otherwise -> print "Something else"<br class="gmail_msg">
<br class="gmail_msg">
You might think that this would catch the exception and print<br class="gmail_msg">
"Something else", but in fact it does not. If others think this is as<br class="gmail_msg">
surprising as I do, then I think we should make throwIO and throw<br class="gmail_msg">
strict, so an exception will never itself be bottom. Using<br class="gmail_msg">
<br class="gmail_msg">
throwIO' !e = throwIO e<br class="gmail_msg">
<br class="gmail_msg">
in the code above instead of throwIO allows the exception to be caught.<br class="gmail_msg">
<br class="gmail_msg">
A more conservative approach might be to just force result of<br class="gmail_msg">
toException before calling raise#, but this only works when users use<br class="gmail_msg">
an explicit type signature to fix the expression type, rather than an<br class="gmail_msg">
exception constructor.<br class="gmail_msg">
<br class="gmail_msg">
David<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Libraries mailing list<br class="gmail_msg">
<a href="mailto:Libraries@haskell.org" class="gmail_msg" target="_blank">Libraries@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br class="gmail_msg">
</blockquote></div>