@hackage throwable-exceptions0.1.0.6

throwable-exceptions gives the easy way to throw exceptions

♦️ 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

  • vvv The summary of the exact examples is available here vvv

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

{-# LANGUAGE TemplateHaskell #-}
module Main where

declareException "MyException"
-- ^^^
-- This is same to write below line yourself
--     data MyException a = MyException
--      { myExceptionCause :: String
--      , MyExceptionClue  :: a --      } deriving (Show, Typeable)
--     instance (Typeable a, Show a) => Exception (MyException a)

main :: IO ()
main = do
  print $ MyException "hi" 10
  print $ myException "poi"

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 !