catch
functions
The catch
family is similar to the try
family:
catchAll :: a -> (Exception -> IO a) -> IO a
catchAllIO :: IO a -> (Exception -> IO a) -> IO a
catch :: (Exception -> Maybe b) -> a -> (b -> IO a) -> IO a
catchIO :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a
The difference is that instead of returning an Either
type as the
result, the catch
functions take a handler argument which is
invoked in the case that an exception was raised while evaluating the
first argument.
catch
and catchIO
take exception predicate arguments in the
same way as try
and tryIO
.
Note that catchIO justIoErrors
is identical to IO.catch
. In
fact, the implementation of IO
errors in GHC uses exceptions
"under the hood".
Also, don't forget to import Prelude hidiing (catch)
when using
this library, to avoid the name clash between Exception.catch
and
IO.catch
.