throwable-exceptions

throwable-exceptions gives the easy way to throw exceptions

https://github.com/aiya000/hs-throwable-exceptions#README.md

Version on this page:0.1.0.5
LTS Haskell 18.28:0.1.0.9
Stackage Nightly 2021-06-14:0.1.0.9
Latest on Hackage:0.1.0.9

See all snapshots throwable-exceptions appears in

MIT licensed by aiya000
Maintained by [email protected]
This version can be pinned in stack with:throwable-exceptions-0.1.0.5@sha256:d62c12c13b457478a59432779d9d53c663d004f8755d940daf63d933266b0ca5,1915

Module documentation for 0.1.0.5

:diamonds: throwable-exceptions :diamonds:

Build Status Hackage

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

:books: Document is available in here :books:

:muscle: Why we should use this ? :muscle:

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

Examples

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

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

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 exception is defined by default :smile:

For example, IOException’s value constructor is not given :cry:
But you can use Control.Exception.Throwable.IOException' instead :dog:

module Main where

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

:+1:

PR is welcome !