partial-handler: A composable exception handler

[ error-handling, exceptions, failure, library, mit ] [ Propose Tags ]

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 a 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, or compose it with other handlers to form a more complex one.


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS] 0.1.0, 0.1.1,, 1.0.1, 1.0.2, 1.0.3
Dependencies base (>=4.6 && <4.8) [details]
License MIT
Copyright (c) 2014, Nikita Volkov
Author Nikita Volkov <>
Maintainer Nikita Volkov <>
Revised Revision 1 made by AdamBergmark at 2015-05-13T15:39:55Z
Category Exceptions, Error Handling
Home page
Bug tracker
Source repo head: git clone git://
Uploaded by NikitaVolkov at 2014-10-18T15:58:50Z
Distributions LTSHaskell:1.0.3, NixOS:1.0.3, Stackage:1.0.3
Reverse Dependencies 2 direct, 50 indirect [details]
Downloads 6159 total (26 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]