exception-utils
Safe HaskellNone
LanguageHaskell2010

Control.Exception.Utils

Description

This is essentially an addition to the exceptions API. Note we do not export that API. This is merely some useful additional utilities.

Since: 0.1

Synopsis

Throwing

Text exception

throwText :: (HasCallStack, MonadThrow m) => Text -> m a Source #

Throws an exception with the Text description.

Since: 0.1

throwString :: (HasCallStack, MonadThrow m) => String -> m a Source #

Throws an exception with the String description.

Since: 0.1

Catching

catchDeep Source #

Arguments

:: forall m e a. (Exception e, HasCallStack, MonadCatch m, MonadIO m, NFData a) 
=> m a 
-> (e -> m a)

The exception handler.

-> m a 

Like catch, except it fully evaluates the result to find impure exceptions.

Since: 0.1

catchDeepSync Source #

Arguments

:: (HasCallStack, MonadCatch m, MonadIO m, NFData a) 
=> m a 
-> (SomeException -> m a)

The exception handler.

-> m a 

catchDeep specialized to synchronous SomeException.

Since: 0.1

catchSync Source #

Arguments

:: (HasCallStack, MonadCatch m) 
=> m a 
-> (SomeException -> m a)

The exception handler.

-> m a 

catch specialized to catch all synchronous SomeExceptions.

catchIf Source #

Arguments

:: forall m e a. (Exception e, HasCallStack, MonadCatch m) 
=> (e -> Bool)

The predicate.

-> m a 
-> (e -> m a)

The exception handler.

-> m a 

Catch an exception only if it satisfies a specific predicate.

handleDeep Source #

Arguments

:: forall m e a. (Exception e, MonadCatch m, MonadIO m, NFData a) 
=> (e -> m a)

The exception handler.

-> m a 
-> m a 

Flipped catchDeep.

Since: 0.1

handleDeepSync Source #

Arguments

:: (MonadCatch m, MonadIO m, NFData a) 
=> (SomeException -> m a)

The exception handler.

-> m a 
-> m a 

Flipped catchDeepSync.

Since: 0.1

handleSync :: (HasCallStack, MonadCatch m) => (SomeException -> m a) -> m a -> m a Source #

Flipped catchSync.

Since: 0.1

handleIf Source #

Arguments

:: forall m e a. (Exception e, HasCallStack, MonadCatch m) 
=> (e -> Bool)

The predicate.

-> (e -> m a)

The exception handler.

-> m a 
-> m a 

Flipped catchIf.

Since: 0.1

tryDeep Source #

Arguments

:: forall m e a. (Exception e, MonadCatch m, MonadIO m, NFData a) 
=> m a

The action.

-> m (Either e a) 

Like try, except it fully evaluates the result to find impure exceptions.

Since: 0.1

tryDeepSync Source #

Arguments

:: (MonadCatch m, MonadIO m, NFData a) 
=> m a

The action.

-> m (Either SomeException a) 

tryDeep specialized to synchronous SomeException.

Since: 0.1

trySync :: (HasCallStack, MonadCatch m) => m a -> m (Either SomeException a) Source #

try specialized to catch all synchronous SomeExceptions.

tryIf Source #

Arguments

:: forall m e a. (Exception e, HasCallStack, MonadCatch m) 
=> (e -> Bool)

The predicate.

-> m a 
-> m (Either e a) 

Catch an exception only if it satisfies a specific predicate.

Cleanup

onSyncException :: (HasCallStack, MonadCatch m) => m a -> m b -> m a Source #

Like onException, except it does not catch asynchronous exception.

Since: 0.1

Exiting

exitFailure :: (HasCallStack, MonadThrow m) => m a Source #

The computation exitFailure is equivalent to exitWith (ExitFailure exitfail), where exitfail is implementation-dependent.

Since: 0.1

exitSuccess :: (HasCallStack, MonadThrow m) => m a Source #

The computation exitSuccess is equivalent to exitWith ExitSuccess, It terminates the program successfully.

Since: 0.1

exitWith :: (HasCallStack, MonadThrow m) => ExitCode -> m a Source #

Lifted exitWith.

Since: 0.1

Misc

isSyncException :: Exception e => e -> Bool Source #

Returns True iff the exception is not a subtype of SomeAsyncException.

Since: 0.1

isAsyncException :: Exception e => e -> Bool Source #

Negation of isSyncException.

Since: 0.1