<div dir="ltr"><div>Don´t tried it and probably it does not even compile, but a possibility could be along these lines:</div><div> </div><div> </div><div>catchExcept excepts handle e= do</div><div> if not . null $ filter ( \(SomeException e') -> typeOf e= typeOf e') excepts</div>
<div> then throw e </div><div> else handle e</div><div> </div><div>use:</div><div> </div><div>u= undefined</div><div> </div><div>excluded= [SomeException (u :: AsyncException), SomeException (u ::ArithException)] </div>
<div> </div><div>sample= expr `catchExcept` excluded $ do</div><div> ....</div><div> ....</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/10 Erik Hesselink <span dir="ltr"><<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Michael,<br>
<br>
We do this as well. In addition to AsyncException, we ignore<br>
BlockedIndefinitelyOnSTM, BlockedIndefinitelyOnMVar and Deadlock. I'm<br>
not sure you can ignore Timeout, since the type is not exported from<br>
System.Timeout. I'm not sure how to classify these, though. They are<br>
in some sense non-recoverable: restarting whatever the thread was<br>
doing is not the right thing to do.<br>
<span class="HOEnZb"><font color="#888888"><br>
Erik<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Wed, Jul 10, 2013 at 8:28 AM, Michael Snoyman <<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>> wrote:<br>
> There's a pattern that arises fairly often: catching every exception thrown<br>
> by code. The naive approach is to do something like:<br>
><br>
> result <- try someCode<br>
> case result of<br>
> Left (e :: SomeException) -> putStrLn $ "It failed: " ++ show e<br>
> Right realValue -> useRealValue<br>
><br>
> This seems perfectly valid, except that it catches a number of exceptions<br>
> which seemingly should not be caught. In particular, it catches the async<br>
> exceptions used by both killThread and timeout.<br>
><br>
> I think it's fair to say that there's not going to be a single function that<br>
> solves all cases correctly, but it is a common enough situation that people<br>
> need to write code that resumes work in the case of an exception that I<br>
> think we need to either have some guidelines for the right approach here, or<br>
> perhaps even a utility function along the lines of:<br>
><br>
> shouldBeCaught :: SomeException -> Bool<br>
><br>
> One first stab at such a function would be to return `False` for<br>
> AsyncException and Timeout, and `True` for everything else, but I'm not<br>
> convinced that this is sufficient. Are there any thoughts on the right<br>
> approach to take here?<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
><br>
<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><br clear="all"><br>-- <br>Alberto.
</div>