On 01/12/12 17:07, Simon Hengel wrote:
> I think there are situation when it is justified to catch almost all
> exceptions.  And people do that a lot, which often leads to ctrl-c not
> properly working (e.g. we had this in HUnit before 1.2.4.2). 

Indeed, and in fact this situation is a very natural occurrence whenever
you are writing code that takes an arbitrary IO action, executes it, and
then returns either the result or the exception that it threw. The code
that I last used for this took advantage of catchJust and looked roughly
like the following:

execute :: IO a → IO (Either SomeException a)
execute action =
catchJust
(\e → case fromException e of {Just (_ :: AsyncException) → Nothing; _ →
Just e})
(Right <$> action)
(return . Left)

Cheers,
Greg

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to