<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&#39;) -&gt; typeOf e= typeOf e&#39;) 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">&lt;<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>&gt;</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&#39;m<br>
not sure you can ignore Timeout, since the type is not exported from<br>
System.Timeout. I&#39;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 &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt; wrote:<br>
&gt; There&#39;s a pattern that arises fairly often: catching every exception thrown<br>
&gt; by code. The naive approach is to do something like:<br>
&gt;<br>
&gt;     result &lt;- try someCode<br>
&gt;     case result of<br>
&gt;         Left (e :: SomeException) -&gt; putStrLn $ &quot;It failed: &quot; ++ show e<br>
&gt;         Right realValue -&gt; useRealValue<br>
&gt;<br>
&gt; This seems perfectly valid, except that it catches a number of exceptions<br>
&gt; which seemingly should not be caught. In particular, it catches the async<br>
&gt; exceptions used by both killThread and timeout.<br>
&gt;<br>
&gt; I think it&#39;s fair to say that there&#39;s not going to be a single function that<br>
&gt; solves all cases correctly, but it is a common enough situation that people<br>
&gt; need to write code that resumes work in the case of an exception that I<br>
&gt; think we need to either have some guidelines for the right approach here, or<br>
&gt; perhaps even a utility function along the lines of:<br>
&gt;<br>
&gt;     shouldBeCaught :: SomeException -&gt; Bool<br>
&gt;<br>
&gt; One first stab at such a function would be to return `False` for<br>
&gt; AsyncException and Timeout, and `True` for everything else, but I&#39;m not<br>
&gt; convinced that this is sufficient. Are there any thoughts on the right<br>
&gt; approach to take here?<br>
&gt;<br>
</div></div><div class="HOEnZb"><div class="h5">&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<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>