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]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 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 Simple
Home page https://github.com/aiya000/throwable-exceptions#README.md
Uploaded by aiya000 at 2017-06-12T02:18:45Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 6392 total (25 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-12 [all 1 reports]

Readme for throwable-exceptions-0.1.0.0

[back to package description]

♦️ throwable-exceptions ♦️

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

💪 Why we should use this ? 💪

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 💪