throwable-exceptions: throwable-exceptions gives the easy way to throw exceptions

[ exception, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

throwable-exceptions gives the easy way to throw exceptions


[Skip to Readme]

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, template-haskell [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 by aiya000 at 2017-09-14T03:36:44Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 6553 total (11 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-09-14 [all 1 reports]

Readme for throwable-exceptions-0.1.0.9

[back to package description]

♦️ throwable-exceptions ♦️

Build Status Hackage

throwable-exceptions gives an easy way to create the data types of Exception instance with TemplateHaskell, and gives simple data types of Exception instance with its value constructor, for your haskell project 🐶

📚 Document is available in here 📚

💪 Why should we use this ? 💪

We want to throw some exception frequently, but the mostly throwable exceptions are not given by base.
throwable-exceptions complements it 👍

Examples


You can create a data type of Exception instance by a line

{-# LANGUAGE TemplateHaskell #-}
module Main where

-- This is same as
--
-- data MyException a = MyException
--  { myExceptionCause :: String
--  , myExceptionClue  :: a
--  } deriving (Show, Typeable)
-- instance (Typeable a, Show a) => Exception (MyException a)
--
declareException "MyException" ["MyException"]

-- This is same as
--
-- data TwoException a =
--  FirstException
--    { firstExceptionCause :: String
--    , firstExceptionClue  :: a
--    } |
--  SecondException
--    { secondExceptionCause :: String
--    , secondExceptionClue  :: a
--    } deriving (Typeable)
--
-- instance Show a => (TwoException a) where
--  ...
-- instance (Typeable a, Show a) => Exception (TwoException a)
--
declareException "TwoException" ["FirstException", "SecondException"]

main :: IO ()
main = do
  print $ ([1..4] `at` 5 :: Either SomeException Int)
  print $ MyException "hi" 10
  print $ myException "poi"
  print $ firstException "chino"
  print $ secondException "cocoa"

Several exceptions are defined by default 😄

For example, IOException's value constructor is not given 😢
But you can use Control.Exception.Throwable.IOException' instead 🐶

module Main where

main :: IO ()
main = do
  throwM $ IOException' "oops!" "in main"
  throwM $ ioException' "oops!"

👍

PR is welcome !