[Haskell-cafe] How to catch all exceptions that could be caught?
Gregory Crosswhite
gcrosswhite at gmail.com
Thu Jan 12 08:29:49 CET 2012
On 01/12/12 17:23, Gregory Crosswhite wrote:
> 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
Ugh, I have no idea why the spacing got eaten; it was meant to look like:
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
More information about the Haskell-Cafe
mailing list