Popularity
4.4
Growing
Activity
0.0
Stable
6
3
2

Monthly Downloads: 27
Programming language: Haskell
License: MIT License
Tags: Control     Exception    

throwable-exceptions alternatives and similar packages

Based on the "exception" category.
Alternatively, view throwable-exceptions alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of throwable-exceptions or a related project?

Add another 'exception' Package

README

:diamonds: throwable-exceptions :diamonds:

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

:books: Document is available in here :books:

:muscle: Why should we 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


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

{-# 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 :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 !