[Haskell-cafe] How to catch all exceptions that could be caught?
Simon Hengel
sol at typeful.net
Thu Jan 12 08:07:55 CET 2012
> > Use SomeException for the type, as it is the base of the exception
> > hierarchy.
>
> But it is usually recommended that you *don't* do this, as it even
> captures Ctrl-c invocations:
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). The way I
deal with this is:
someAction `catches` [
-- Re-throw AsyncException, otherwise execution will not terminate
-- on SIGINT (ctrl-c). All AsyncExceptions are re-thrown (not
-- just UserInterrupt) because all of them indicate severe
-- conditions and should not occur during normal operation.
Handler (\e -> throw (e :: AsyncException)),
Handler (\e -> yourHandler $ e :: SomeException)
]
Cheers,
Simon
More information about the Haskell-Cafe
mailing list