Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
When you've caught all the exceptions that can be handled safely, this is what you're left with.
runEitherIO . fromIO ≡ id
It is intended that you use qualified imports with this library.
import UnexceptionalIO (UIO) import qualified UnexceptionalIO as UIO
Synopsis
- data UIO a
- class Monad m => Unexceptional m where
- fromIO :: Unexceptional m => IO a -> m (Either SomeNonPseudoException a)
- fromIO' :: (Exception e, Unexceptional m) => (SomeNonPseudoException -> e) -> IO a -> m (Either e a)
- run :: UIO a -> IO a
- runEitherIO :: Exception e => UIO (Either e a) -> IO a
- unsafeFromIO :: Unexceptional m => IO a -> m a
- data SomeNonPseudoException
- data PseudoException
- data ProgrammerError
- = TypeError TypeError
- | ArithException ArithException
- | ArrayException ArrayException
- | AssertionFailed AssertionFailed
- | ErrorCall ErrorCall
- | NestedAtomically NestedAtomically
- | NoMethodError NoMethodError
- | PatternMatchFail PatternMatchFail
- | RecConError RecConError
- | RecSelError RecSelError
- | RecUpdError RecSelError
- data ExternalError
- bracket :: Unexceptional m => UIO a -> (a -> UIO ()) -> (a -> UIO c) -> m c
- forkFinally :: Unexceptional m => UIO a -> (Either PseudoException a -> UIO ()) -> m ThreadId
- fork :: Unexceptional m => UIO () -> m ThreadId
- newtype ChildThreadError = ChildThreadError PseudoException
Documentation
Like IO, but throws only PseudoException
class Monad m => Unexceptional m where Source #
Monads in which UIO
computations may be embedded
Instances
Unexceptional IO Source # | |
Unexceptional UIO Source # | |
fromIO :: Unexceptional m => IO a -> m (Either SomeNonPseudoException a) Source #
Catch any exception but PseudoException
in an IO
action
:: (Exception e, Unexceptional m) | |
=> (SomeNonPseudoException -> e) | Default if an unexpected exception occurs |
-> IO a | |
-> m (Either e a) |
Catch any e
in an IO
action, with a default mapping for
unexpected cases
Unsafe entry points
unsafeFromIO :: Unexceptional m => IO a -> m a Source #
You promise there are no exceptions but PseudoException
thrown by this IO
action
Pseudo exceptions
data SomeNonPseudoException Source #
Every SomeException
but PseudoException
Instances
Show SomeNonPseudoException Source # | |
Defined in UnexceptionalIO showsPrec :: Int -> SomeNonPseudoException -> ShowS # show :: SomeNonPseudoException -> String # showList :: [SomeNonPseudoException] -> ShowS # | |
Exception SomeNonPseudoException Source # | |
data PseudoException Source #
Not everything handled by the exception system is a run-time error you can handle. This is the class of unrecoverable pseudo-exceptions.
Additionally, except for ExitCode
any of these pseudo-exceptions
you could never guarantee to have caught. Since they can come
from anywhere at any time, we could never guarentee that UIO
does
not contain them.
ProgrammerError ProgrammerError | Mistakes programmers make |
ExternalError ExternalError | Errors thrown by the runtime |
Exit ExitCode | Process exit requests |
Instances
Show PseudoException Source # | |
Defined in UnexceptionalIO showsPrec :: Int -> PseudoException -> ShowS # show :: PseudoException -> String # showList :: [PseudoException] -> ShowS # | |
Exception PseudoException Source # | |
Defined in UnexceptionalIO |
data ProgrammerError Source #
Instances
Show ProgrammerError Source # | |
Defined in UnexceptionalIO showsPrec :: Int -> ProgrammerError -> ShowS # show :: ProgrammerError -> String # showList :: [ProgrammerError] -> ShowS # | |
Exception ProgrammerError Source # | |
Defined in UnexceptionalIO |
data ExternalError Source #
Pseudo-exceptions thrown by the runtime environment
Instances
Show ExternalError Source # | |
Defined in UnexceptionalIO showsPrec :: Int -> ExternalError -> ShowS # show :: ExternalError -> String # showList :: [ExternalError] -> ShowS # | |
Exception ExternalError Source # | |
Defined in UnexceptionalIO |
Pseudo exception helpers
bracket :: Unexceptional m => UIO a -> (a -> UIO ()) -> (a -> UIO c) -> m c Source #
When you're doing resource handling, PseudoException
matters.
You still need to use the bracket
pattern to handle cleanup.
forkFinally :: Unexceptional m => UIO a -> (Either PseudoException a -> UIO ()) -> m ThreadId Source #
Mirrors forkFinally
, but since the body is UIO
,
the thread must terminate successfully or because of PseudoException
fork :: Unexceptional m => UIO () -> m ThreadId Source #
Mirrors forkIO
, but re-throws errors to the parent thread
- Ignores manual thread kills, since those are on purpose.
- Re-throws async exceptions (
SomeAsyncException
) as is. - Re-throws
ExitCode
as is in an attempt to exit with the requested code. - Wraps synchronous
PseudoException
in asyncChildThreadError
.
newtype ChildThreadError Source #
Async signal that a child thread ended due to non-async PseudoException
Instances
Show ChildThreadError Source # | |
Defined in UnexceptionalIO showsPrec :: Int -> ChildThreadError -> ShowS # show :: ChildThreadError -> String # showList :: [ChildThreadError] -> ShowS # | |
Exception ChildThreadError Source # | |
Defined in UnexceptionalIO |