The throwable-exceptions package

[Tags:library, mit, test]

throwable-exceptions gives the easy way to throw exceptions


[Skip to Readme]

Properties

Versions 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
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 Wed Jul 5 01:34:36 UTC 2017 by aiya000
Distributions LTSHaskell:0.1.0.8, NixOS:0.1.0.8, Stackage:0.1.0.8
Downloads 330 total (43 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-07-05 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for throwable-exceptions

Readme for throwable-exceptions-0.1.0.8

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