lifted-base
CopyrightBas van Dijk Anders Kaseorg
LicenseBSD-style
MaintainerBas van Dijk <v.dijk.bas@gmail.com>
Stabilityexperimental
Portabilitynon-portable (extended exceptions)
Safe HaskellSafe
LanguageHaskell98

Control.Exception.Lifted

Description

This is a wrapped version of Control.Exception with types generalized from IO to all monads in either MonadBase or MonadBaseControl.

Synopsis

Documentation

assert :: Bool -> a -> a #

mapException :: (Exception e1, Exception e2) => (e1 -> e2) -> a -> a #

tryWithContext :: Exception e => IO a -> IO (Either (ExceptionWithContext e) a) #

throw :: forall a e. (HasCallStack, Exception e) => e -> a #

addExceptionContext :: ExceptionAnnotation a => a -> SomeException -> SomeException #

someExceptionContext :: SomeException -> ExceptionContext #

annotateIO :: ExceptionAnnotation e => e -> IO a -> IO a #

catchNoPropagate :: Exception e => IO a -> (ExceptionWithContext e -> IO a) -> IO a #

interruptible :: IO a -> IO a #

newtype NoMethodError #

Constructors

NoMethodError String 

Instances

Instances details
Exception NoMethodError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show NoMethodError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> NoMethodError -> ShowS

show :: NoMethodError -> String

showList :: [NoMethodError] -> ShowS

data NonTermination #

Constructors

NonTermination 

Instances

Instances details
Exception NonTermination # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show NonTermination # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> NonTermination -> ShowS

show :: NonTermination -> String

showList :: [NonTermination] -> ShowS

newtype RecConError #

Constructors

RecConError String 

Instances

Instances details
Exception RecConError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show RecConError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> RecConError -> ShowS

show :: RecConError -> String

showList :: [RecConError] -> ShowS

newtype RecSelError #

Constructors

RecSelError String 

Instances

Instances details
Exception RecSelError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show RecSelError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> RecSelError -> ShowS

show :: RecSelError -> String

showList :: [RecSelError] -> ShowS

newtype RecUpdError #

Constructors

RecUpdError String 

Instances

Instances details
Exception RecUpdError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show RecUpdError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> RecUpdError -> ShowS

show :: RecUpdError -> String

showList :: [RecUpdError] -> ShowS

newtype TypeError #

Constructors

TypeError String 

Instances

Instances details
Exception TypeError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Show TypeError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

showsPrec :: Int -> TypeError -> ShowS

show :: TypeError -> String

showList :: [TypeError] -> ShowS

data ErrorCall #

Constructors

ErrorCall String 

Bundled Patterns

pattern ErrorCallWithLocation :: String -> String -> ErrorCall 

Instances

Instances details
Exception ErrorCall # 
Instance details

Defined in GHC.Internal.Exception

Show ErrorCall # 
Instance details

Defined in GHC.Internal.Exception

Methods

showsPrec :: Int -> ErrorCall -> ShowS

show :: ErrorCall -> String

showList :: [ErrorCall] -> ShowS

Eq ErrorCall # 
Instance details

Defined in GHC.Internal.Exception

Methods

(==) :: ErrorCall -> ErrorCall -> Bool

(/=) :: ErrorCall -> ErrorCall -> Bool

Ord ErrorCall # 
Instance details

Defined in GHC.Internal.Exception

Methods

compare :: ErrorCall -> ErrorCall -> Ordering

(<) :: ErrorCall -> ErrorCall -> Bool

(<=) :: ErrorCall -> ErrorCall -> Bool

(>) :: ErrorCall -> ErrorCall -> Bool

(>=) :: ErrorCall -> ErrorCall -> Bool

max :: ErrorCall -> ErrorCall -> ErrorCall

min :: ErrorCall -> ErrorCall -> ErrorCall

class (Typeable e, Show e) => Exception e where #

Minimal complete definition

Nothing

Methods

toException :: e -> SomeException #

fromException :: SomeException -> Maybe e #

displayException :: e -> String #

backtraceDesired :: e -> Bool #

Instances

Instances details
Exception Timeout # 
Instance details

Defined in System.Timeout

Methods

toException :: Timeout -> SomeException #

fromException :: SomeException -> Maybe Timeout #

displayException :: Timeout -> String #

backtraceDesired :: Timeout -> Bool #

Exception Void # 
Instance details

Defined in GHC.Internal.Exception.Type

Methods

toException :: Void -> SomeException #

fromException :: SomeException -> Maybe Void #

displayException :: Void -> String #

backtraceDesired :: Void -> Bool #

Exception NestedAtomically # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception NoMatchingContinuationPrompt # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Methods

toException :: NoMatchingContinuationPrompt -> SomeException #

fromException :: SomeException -> Maybe NoMatchingContinuationPrompt #

displayException :: NoMatchingContinuationPrompt -> String #

backtraceDesired :: NoMatchingContinuationPrompt -> Bool #

Exception NoMethodError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception NonTermination # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception PatternMatchFail # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception RecConError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception RecSelError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception RecUpdError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception TypeError # 
Instance details

Defined in GHC.Internal.Control.Exception.Base

Exception ErrorCall # 
Instance details

Defined in GHC.Internal.Exception

Exception ArithException # 
Instance details

Defined in GHC.Internal.Exception.Type

Exception SomeException # 
Instance details

Defined in GHC.Internal.Exception.Type

Exception AllocationLimitExceeded # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception ArrayException # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception AssertionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception AsyncException # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception BlockedIndefinitelyOnMVar # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception BlockedIndefinitelyOnSTM # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception CompactionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception Deadlock # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception ExitCode # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

toException :: ExitCode -> SomeException #

fromException :: SomeException -> Maybe ExitCode #

displayException :: ExitCode -> String #

backtraceDesired :: ExitCode -> Bool #

Exception FixIOException # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

toException :: FixIOException -> SomeException #

fromException :: SomeException -> Maybe FixIOException #

displayException :: FixIOException -> String #

backtraceDesired :: FixIOException -> Bool #

Exception IOException # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception SomeAsyncException # 
Instance details

Defined in GHC.Internal.IO.Exception

Exception a => Exception (ExceptionWithContext a) # 
Instance details

Defined in GHC.Internal.Exception.Type

Exception e => Exception (NoBacktrace e) # 
Instance details

Defined in GHC.Internal.Exception.Type

data ExceptionWithContext a #

Constructors

ExceptionWithContext ExceptionContext a 

Instances

Instances details
Exception a => Exception (ExceptionWithContext a) # 
Instance details

Defined in GHC.Internal.Exception.Type

Show a => Show (ExceptionWithContext a) # 
Instance details

Defined in GHC.Internal.Exception.Type

Methods

showsPrec :: Int -> ExceptionWithContext a -> ShowS

show :: ExceptionWithContext a -> String

showList :: [ExceptionWithContext a] -> ShowS

newtype NoBacktrace e #

Constructors

NoBacktrace e 

Instances

Instances details
Exception e => Exception (NoBacktrace e) # 
Instance details

Defined in GHC.Internal.Exception.Type

Show e => Show (NoBacktrace e) # 
Instance details

Defined in GHC.Internal.Exception.Type

Methods

showsPrec :: Int -> NoBacktrace e -> ShowS

show :: NoBacktrace e -> String

showList :: [NoBacktrace e] -> ShowS

data SomeException #

Constructors

(Exception e, HasExceptionContext) => SomeException e 

Instances

Instances details
Exception SomeException # 
Instance details

Defined in GHC.Internal.Exception.Type

Show SomeException # 
Instance details

Defined in GHC.Internal.Exception.Type

Methods

showsPrec :: Int -> SomeException -> ShowS

show :: SomeException -> String

showList :: [SomeException] -> ShowS

data WhileHandling #

Instances

Instances details
ExceptionAnnotation WhileHandling # 
Instance details

Defined in GHC.Internal.Exception.Type

Show WhileHandling # 
Instance details

Defined in GHC.Internal.Exception.Type

Methods

showsPrec :: Int -> WhileHandling -> ShowS

show :: WhileHandling -> String

showList :: [WhileHandling] -> ShowS

data MaskingState #

Instances

Instances details
Show MaskingState # 
Instance details

Defined in GHC.Internal.IO

Methods

showsPrec :: Int -> MaskingState -> ShowS

show :: MaskingState -> String

showList :: [MaskingState] -> ShowS

Eq MaskingState # 
Instance details

Defined in GHC.Internal.IO

Methods

(==) :: MaskingState -> MaskingState -> Bool

(/=) :: MaskingState -> MaskingState -> Bool

newtype AssertionFailed #

Constructors

AssertionFailed String 

Instances

Instances details
Exception AssertionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Show AssertionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

showsPrec :: Int -> AssertionFailed -> ShowS

show :: AssertionFailed -> String

showList :: [AssertionFailed] -> ShowS

newtype CompactionFailed #

Constructors

CompactionFailed String 

Instances

Instances details
Exception CompactionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Show CompactionFailed # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

showsPrec :: Int -> CompactionFailed -> ShowS

show :: CompactionFailed -> String

showList :: [CompactionFailed] -> ShowS

data Deadlock #

Constructors

Deadlock 

Instances

Instances details
Exception Deadlock # 
Instance details

Defined in GHC.Internal.IO.Exception

Show Deadlock # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

showsPrec :: Int -> Deadlock -> ShowS

show :: Deadlock -> String

showList :: [Deadlock] -> ShowS

data IOException #

Instances

Instances details
Exception IOException # 
Instance details

Defined in GHC.Internal.IO.Exception

Show IOException # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

showsPrec :: Int -> IOException -> ShowS

show :: IOException -> String

showList :: [IOException] -> ShowS

Eq IOException # 
Instance details

Defined in GHC.Internal.IO.Exception

Methods

(==) :: IOException -> IOException -> Bool

(/=) :: IOException -> IOException -> Bool

Throwing exceptions

throwIO :: (MonadBase IO m, Exception e) => e -> m a Source #

Generalized version of throwIO.

ioError :: MonadBase IO m => IOError -> m a Source #

Generalized version of ioError.

throwTo :: (MonadBase IO m, Exception e) => ThreadId -> e -> m () Source #

Generalized version of throwTo.

Catching exceptions

The catch functions

catch Source #

Arguments

:: (MonadBaseControl IO m, Exception e) 
=> m a

The computation to run

-> (e -> m a)

Handler to invoke if an exception is raised

-> m a 

Generalized version of catch.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

catches :: MonadBaseControl IO m => m a -> [Handler m a] -> m a Source #

Generalized version of catches.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

data Handler (m :: Type -> Type) a Source #

Generalized version of Handler.

Constructors

Exception e => Handler (e -> m a) 

catchJust Source #

Arguments

:: (MonadBaseControl IO m, Exception e) 
=> (e -> Maybe b)

Predicate to select exceptions

-> m a

Computation to run

-> (b -> m a)

Handler

-> m a 

Generalized version of catchJust.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

The handle functions

handle :: (MonadBaseControl IO m, Exception e) => (e -> m a) -> m a -> m a Source #

Generalized version of handle.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

handleJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a Source #

Generalized version of handleJust.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

The try functions

try :: (MonadBaseControl IO m, Exception e) => m a -> m (Either e a) Source #

Generalized version of try.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

tryJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a) Source #

Generalized version of tryJust.

Note, when the given computation throws an exception any monadic side effects in m will be discarded.

The evaluate function

evaluate :: MonadBase IO m => a -> m a Source #

Generalized version of evaluate.

Asynchronous Exceptions

Asynchronous exception control

The following functions allow a thread to control delivery of asynchronous exceptions during a critical region.

mask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b Source #

Generalized version of mask.

mask_ :: MonadBaseControl IO m => m a -> m a Source #

Generalized version of mask_.

uninterruptibleMask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b Source #

Generalized version of uninterruptibleMask.

uninterruptibleMask_ :: MonadBaseControl IO m => m a -> m a Source #

Generalized version of uninterruptibleMask_.

getMaskingState :: MonadBase IO m => m MaskingState Source #

Generalized version of getMaskingState.

allowInterrupt :: MonadBase IO m => m () Source #

Generalized version of allowInterrupt.

Brackets

bracket Source #

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> (a -> m b)

computation to run last ("release resource")

-> (a -> m c)

computation to run in-between

-> m c 

Generalized version of bracket.

Note:

  • When the "acquire" or "release" computations throw exceptions any monadic side effects in m will be discarded.
  • When the "in-between" computation throws an exception any monadic side effects in m produced by that computation will be discarded but the side effects of the "acquire" or "release" computations will be retained.
  • Also, any monadic side effects in m of the "release" computation will be discarded; it is run only for its side effects in IO.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp (bracket acquire release)

bracket_ Source #

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> m b

computation to run last ("release resource")

-> m c

computation to run in-between

-> m c 

Generalized version of bracket_.

Note any monadic side effects in m of both the "acquire" and "release" computations will be discarded. To keep the monadic side effects of the "acquire" computation, use bracket with constant functions instead.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp_ (bracket_ acquire release)

bracketOnError Source #

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first ("acquire resource")

-> (a -> m b)

computation to run last ("release resource")

-> (a -> m c)

computation to run in-between

-> m c 

Generalized version of bracketOnError.

Note:

  • When the "acquire" or "release" computations throw exceptions any monadic side effects in m will be discarded.
  • When the "in-between" computation throws an exception any monadic side effects in m produced by that computation will be discarded but the side effects of the "acquire" computation will be retained.
  • Also, any monadic side effects in m of the "release" computation will be discarded; it is run only for its side effects in IO.

Note that when your acquire and release computations are of type IO it will be more efficient to write:

liftBaseOp (bracketOnError acquire release)

Utilities

finally Source #

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first

-> m b

computation to run afterward (even if an exception was raised)

-> m a 

Generalized version of finally.

Note, any monadic side effects in m of the "afterward" computation will be discarded.

onException :: MonadBaseControl IO m => m a -> m b -> m a Source #

Generalized version of onException.

Note, any monadic side effects in m of the "afterward" computation will be discarded.