throwable-exceptions: throwable-exceptions gives the exception's value constructors

[ exception, library, mit ] [ Propose Tags ]

throwable-exceptions gives the exception's value constructors

[Skip to Readme]
Versions [faq],,,,,,,,,
Dependencies base (>=4.7 && <5), safe-exceptions [details]
License MIT
Copyright aiya000
Author aiya000
Category Exception
Home page
Uploaded by aiya000 at Tue Jun 13 14:59:45 UTC 2017
Distributions LTSHaskell:, NixOS:, Stackage:
Downloads 2539 total (80 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2017-06-13 [all 1 reports]




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 !