The throwable-exceptions package

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

throwable-exceptions gives the exception's value constructors


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.0.8, 0.1.0.9
Dependencies base (>=4.7 && <5), safe-exceptions [details]
License MIT
Copyright aiya000
Author aiya000
Maintainer aiya000.develop@gmail.com
Category Exception
Home page https://github.com/aiya000/hs-throwable-exceptions#README.md
Uploaded Mon Jun 12 05:10:45 UTC 2017 by aiya000
Distributions LTSHaskell:0.1.0.9, NixOS:0.1.0.9, Stackage:0.1.0.9
Downloads 364 total (33 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-12 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for throwable-exceptions-0.1.0.3

[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:

:+1:

PR is welcome !