-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A composable exception handler -- -- If you have ever had to compose an exception handler for exceptions of -- multiple types, you know how frustraiting it can get. This library -- approaches this issue by providing a composable exception handler -- type, which has a Monoid instance. -- -- Composability means that you can define custom partial handlers and -- reuse them by composing other handlers from them. -- -- Here is an example of a composable partial handler, which only defines -- what to do in case of a ThreadKilled exception (the code uses the -- LambdaCase extension): -- --
--   ignoreThreadKilled :: PartialHandler ()
--   ignoreThreadKilled =
--     typed $ \case
--       ThreadKilled -> Just $ return ()
--       _ -> Nothing
--   
-- -- Here's how you can construct a handler of type SomeException -> -- IO () using this library: -- --
--   totalizeRethrowing $
--     ignoreThreadKilled <>
--     onAlreadyExists (putStrLn "Already exists")
--   
-- -- and here is how you would do it traditionally (with the MultiWayIf -- extension): -- --
--   \e -> if
--     | Just ThreadKilled <- fromException e ->
--         return ()
--     | Just e' <- fromException e, isAlreadyExistsError e' ->
--         putStrLn "Already exists"
--     | otherwise ->
--         throwIO e
--   
-- -- Putting all the syntactic trickery to make it shorter aside, this -- handler is a monolith block of code. Unlike with PartialHandler you -- can neither decompose it into simpler ones, nor compose it with other -- handlers to form a more complex one. @package partial-handler @version 1.0.1 module PartialHandler -- | A composable exception handler. newtype PartialHandler a PartialHandler :: (SomeException -> Maybe (IO a)) -> PartialHandler a -- | A function, which handles all exceptions. -- -- Can be used as a parameter to standard functions like catch and -- handle, or to process the result of try. type TotalHandler a = SomeException -> IO a -- | Convert a partial handler into a total handler, which throws an error -- for unhandled cases. In other words, the produced total handler is -- itself a partial function, so use this only in cases when an unhandled -- exception should be considered as a bug. totalize :: PartialHandler a -> TotalHandler a -- | Convert a partial handler into a total handler, which rethrows all -- unhandled exceptions. totalizeRethrowing :: PartialHandler a -> TotalHandler a -- | Convert a partial handler into a total handler, which rethrows all -- unhandled exceptions to the specified thread and the current thread. totalizeRethrowingTo :: ThreadId -> PartialHandler a -> TotalHandler a -- | Convert a partial handler into a total handler, which rethrows all -- unhandled exceptions to the specified thread, while the current thread -- continues the execution. totalizeRethrowingTo_ :: ThreadId -> PartialHandler () -> TotalHandler () -- | A handler of exceptions of a specific type. typed :: Exception e => (e -> Maybe (IO a)) -> PartialHandler a -- | A handler of the ThreadKilled exception. onThreadKilled :: IO a -> PartialHandler a -- | A handler of all exceptions of type IOError by their type. onIOErrorByType :: (IOErrorType -> Maybe (IO a)) -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isAlreadyExistsError predicate. onAlreadyExists :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isDoesNotExistError predicate. onDoesNotExist :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isAlreadyInUseError predicate. onAlreadyInUse :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isFullError predicate. onFull :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isEOFError predicate. onEOF :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isIllegalOperation predicate. onIllegalOperation :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isPermissionError predicate. onPermission :: IO a -> PartialHandler a -- | A handler of an IOError exception with type satisfying the -- isUserError predicate. onUser :: IO a -> PartialHandler a instance GHC.Base.Monoid (PartialHandler.PartialHandler a)