The throwable-exceptions package

[ Tags: exception, library, mit ] [ Propose Tags ]

throwable-exceptions gives the exception's value constructors

[Skip to Readme]


Dependencies base (>=4.7 && <5), safe-exceptions [details]
License MIT
Copyright aiya000
Author aiya000
Category Exception
Home page
Uploaded Mon Jun 12 05:10:45 UTC 2017 by aiya000
Distributions LTSHaskell:, NixOS:, Stackage:, Tumbleweed:
Downloads 1493 total (712 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-12 [all 1 reports]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for throwable-exceptions-

[back to package description]

:diamonds: throwable-exceptions :diamonds:

Build Status Hackage

throwable-exceptions gives the exception's value constructors for your haskell project :dog:

Document is available in here

:muscle: Why we should use this ? :muscle:

The situation that we want to throw the specific exception is happened frequently, but many general exceptions are not given by base.

For example, IOException's value constructor is not given.

import Control.Exception.Safe (MonadThrow, throwM, IOException(..), try, Exception, SomeException)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Either (runEitherT)

readFileOrError :: (MonadThrow m, MonadIO m) => FilePath -> m String
readFileOrError path = do
  xOrErr <- liftIO . try $ readFile path
  case xOrErr of
    Left e -> throwM . IOException $ show (e :: SomeException)
    Right a -> return a

main :: IO ()
main = do
  xOrErr <- runEitherT $ readFileOrError "Main.hs"
  case xOrErr of
    Left e -> putStrLn $ "oops: " ++ show (e :: SomeException)
    Right a -> putStrLn a

-- Result output vv
-- Data constructor not in scope: IOException :: [Char] -> e1

But you have not to define a specific exception yourself if you use this :muscle:


PR is welcome !