This package provides Control.Effect.Exception
, a module that wraps the Control.Exception
API from base
with the vocabulary provided by the fused-effects
library. These functions interact with GHC's support for dynamic exceptions, including functions like catch
for exception handling and bracket
for resource management.
Please be aware that injudicious use of these functions may provoke surprising interactions with carriers that thread a monadic state as a parameter, à la the Control.Carrier.State
types provided by fused-effects
. For example, a function like finally
, which does not thread any state from its body to its handler block, may discard state writes in cleanup handlers:
discardsState :: IO Char
discardsState = execState 'a' ((throwIO (userError "urk") `finally` put @Char 'z')
`catch` (\(_ :: IOException) -> pure ()))
Though the put @Char 'z'
statement is evaluated, its effect is ultimately discarded; the result of executing the above is 'a'
. If this behavior is a concern, use the Control.Carrier.State.IORef
carrier from fused-effects
itself.
Prior versions of this package provided a Catch
effect; this has been excised in favor of the more-general Control.Effect.Exception
, which provides more functionality without requiring any additional carriers beyond a Lift IO
effect.