Exception

ghc-8.6.3: The GHC API

Safe Haskell | Safe
Language | Haskell2010

Exception

Synopsis

- module Control.Exception
- 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
- catchIO :: IO a -> (IOException -> IO a) -> IO a
- handleIO :: (IOException -> IO a) -> IO a -> IO a
- tryIO :: IO a -> IO (Either IOException a)
- gtry :: (ExceptionMonad m, Exception e) => m a -> m (Either e a)
- ghandle :: (ExceptionMonad m, Exception e) => (e -> m a) -> m a -> m a
- gonException :: ExceptionMonad m => m a -> m b -> m a

# Documentation

module Control.Exception

class MonadIO m => ExceptionMonad m where #

A monad that can catch exceptions. A minimal definition requires a definition of `gcatch`.

Implementations on top of `IO` should implement `gmask` to eventually call the primitive `mask`. These are used for implementations that support asynchronous exceptions. The default implementations of `gbracket` and `gfinally` use `gmask` thus rarely require overriding.

Minimal complete definition

gcatch, gmask

Methods

gcatch :: Exception e => m a -> (e -> m a) -> m a #

Generalised version of `catch`, allowing an arbitrary exception handling monad instead of just `IO`.

gmask :: ((m a -> m a) -> m b) -> m b #

Generalised version of `mask_`, allowing an arbitrary exception handling monad instead of just `IO`.

gbracket :: m a -> (a -> m b) -> (a -> m c) -> m c #

Generalised version of `bracket`, allowing an arbitrary exception handling monad instead of just `IO`.

gfinally :: m a -> m b -> m a #

Generalised version of `finally`, allowing an arbitrary exception handling monad instead of just `IO`.

Instances

ExceptionMonad IO # |
Instance details Defined in Exception Methods gcatch :: Exception e => IO a -> (e -> IO a) -> IO a # gmask :: ((IO a -> IO a) -> IO b) -> IO b # gbracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c # gfinally :: IO a -> IO b -> IO a #
ExceptionMonad Ghc # |
Instance details Defined in GhcMonad Methods gcatch :: Exception e => Ghc a -> (e -> Ghc a) -> Ghc a # gmask :: ((Ghc a -> Ghc a) -> Ghc b) -> Ghc b # gbracket :: Ghc a -> (a -> Ghc b) -> (a -> Ghc c) -> Ghc c # gfinally :: Ghc a -> Ghc b -> Ghc a #
ExceptionMonad (IOEnv a) # |
Instance details Defined in IOEnv Methods gcatch :: Exception e => IOEnv a a0 -> (e -> IOEnv a a0) -> IOEnv a a0 # gmask :: ((IOEnv a a0 -> IOEnv a a0) -> IOEnv a b) -> IOEnv a b # gbracket :: IOEnv a a0 -> (a0 -> IOEnv a b) -> (a0 -> IOEnv a c) -> IOEnv a c # gfinally :: IOEnv a a0 -> IOEnv a b -> IOEnv a a0 #
ExceptionMonad m => ExceptionMonad (GhcT m) # |
Instance details Defined in GhcMonad Methods gcatch :: Exception e => GhcT m a -> (e -> GhcT m a) -> GhcT m a # gmask :: ((GhcT m a -> GhcT m a) -> GhcT m b) -> GhcT m b # gbracket :: GhcT m a -> (a -> GhcT m b) -> (a -> GhcT m c) -> GhcT m c # gfinally :: GhcT m a -> GhcT m b -> GhcT m a #

catchIO :: IO a -> (IOException -> IO a) -> IO a #

handleIO :: (IOException -> IO a) -> IO a -> IO a #

tryIO :: IO a -> IO (Either IOException a) #

gtry :: (ExceptionMonad m, Exception e) => m a -> m (Either e a) #

ghandle :: (ExceptionMonad m, Exception e) => (e -> m a) -> m a -> m a #

Generalised version of `handle`, allowing an arbitrary exception handling monad instead of just `IO`.

gonException :: ExceptionMonad m => m a -> m b -> m a #

Always executes the first argument. If this throws an exception the second argument is executed and the exception is raised again.