{-# OPTIONS_GHC -fno-warn-deprecations #-}
module Exception
(
module Control.Exception,
module Exception
)
where
import Control.Exception
import Control.Monad.IO.Class
catchIO :: IO a -> (IOException -> IO a) -> IO a
catchIO = Control.Exception.catch
handleIO :: (IOException -> IO a) -> IO a -> IO a
handleIO = flip catchIO
tryIO :: IO a -> IO (Either IOException a)
tryIO = try
class MonadIO m => ExceptionMonad m where
gcatch :: Exception e => m a -> (e -> m a) -> m a
gmask :: ((m a -> m a) -> m b) -> m b
gbracket :: m a -> (a -> m b) -> (a -> m c) -> m c
gfinally :: m a -> m b -> m a
gbracket before after thing =
gmask $ \restore -> do
a <- before
r <- restore (thing a) `gonException` after a
_ <- after a
return r
a `gfinally` sequel =
gmask $ \restore -> do
r <- restore a `gonException` sequel
_ <- sequel
return r
instance ExceptionMonad IO where
gcatch = Control.Exception.catch
gmask f = mask (\x -> f x)
gtry :: (ExceptionMonad m, Exception e) => m a -> m (Either e a)
gtry act = gcatch (act >>= \a -> return (Right a))
(\e -> return (Left e))
ghandle :: (ExceptionMonad m, Exception e) => (e -> m a) -> m a -> m a
ghandle = flip gcatch
gonException :: (ExceptionMonad m) => m a -> m b -> m a
gonException ioA cleanup = ioA `gcatch` \e ->
do _ <- cleanup
liftIO $ throwIO (e :: SomeException)