packages feed

throwable-exceptions (empty) → 0.1.0.0

raw patch · 7 files changed

+131/−0 lines, 7 filesdep +basedep +eitherdep +safe-exceptionssetup-changed

Dependencies added: base, either, safe-exceptions, tasty, tasty-discover, tasty-hunit, text, throwable-exceptions

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2017 aiya000++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ README.md view
@@ -0,0 +1,35 @@+# :diamonds: throwable-exceptions :diamonds:+throwable-exceptions gives the exception's value constructors for your haskell project :dog:+++# :muscle: Why we should use this ? :muscle:+The situation that we want to throw the specific exception is happened frequently,+but many general exceptions are not given by base.++For example, [IOException](https://hackage.haskell.org/package/base-4.9.1.0/docs/Control-Exception.html#t:IOException)'s value constructor is not given.++```haskell+import Control.Exception.Safe (MonadThrow, throwM, IOException(..), try, Exception, SomeException)+import Control.Monad.IO.Class (MonadIO, liftIO)+import Control.Monad.Trans.Either (runEitherT)++readFileOrError :: (MonadThrow m, MonadIO m) => FilePath -> m String+readFileOrError path = do+  xOrErr <- liftIO . try $ readFile path+  case xOrErr of+    Left e -> throwM . IOException $ show (e :: SomeException)+    Right a -> return a++main :: IO ()+main = do+  xOrErr <- runEitherT $ readFileOrError "Main.hs"+  case xOrErr of+    Left e -> putStrLn $ "oops: " ++ show (e :: SomeException)+    Right a -> putStrLn a++-- Result output vv+-- Data constructor not in scope: IOException :: [Char] -> e1+```++But you have not to define a specific exception yourself+if you use this :muscle:
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Control/Exception/Throwable.hs view
@@ -0,0 +1,20 @@+module Control.Exception.Throwable+  ( IOException' (..)+  ) where++import Control.Exception.Safe (Exception)+++-- | Simular to @Control.Exception.IOException@+data IOException' = IOException' { ioExceptionCause :: String }+                  | FileNotFoundException { fileNotFoundCause :: String }+  deriving (Read, Show)++instance Exception IOException'+++-- Like java.lang.IllegalArgumentException+data IllegalArgumentException = IllegalArgumentException { illegalArgumentCause :: String }+  deriving (Read, Show)++instance Exception IllegalArgumentException
+ test/Control/Exception/ThrowableTest.hs view
@@ -0,0 +1,11 @@+module Control.Exception.ThrowableTest where++import Control.Exception.Safe (MonadThrow, throwM)+import Control.Monad.Trans.Either (runEitherT)+import Test.Tasty (TestTree)+import Test.Tasty.HUnit (testCase, assertFailure, (@?=), Assertion)+import qualified Control.Exception.Throwable as ET+++test_ioexception_prim :: [TestTree]+test_ioexception_prim = []
+ test/Tasty.hs view
@@ -0,0 +1,3 @@+{-#+  OPTIONS_GHC -F -pgmF tasty-discover+#-}
+ throwable-exceptions.cabal view
@@ -0,0 +1,39 @@+name:                throwable-exceptions+version:             0.1.0.0+synopsis:            throwable-exceptions gives the exception's value constructors+description:         throwable-exceptions gives the exception's value constructors+homepage:            https://github.com/aiya000/throwable-exceptions#README.md+license:             MIT+license-file:        LICENSE+author:              aiya000+maintainer:          aiya000.develop@gmail.com+copyright:           aiya000+category:            Simple+build-type:          Simple+cabal-version:       >=1.10+extra-source-files:  README.md++library+  hs-source-dirs:      src+  default-language:    Haskell2010+  ghc-options:         -Wall -Wno-name-shadowing -Wno-unused-do-bind -Wunused-top-binds+  exposed-modules:     Control.Exception.Throwable+  build-depends:       base >= 4.7 && < 5+                     , safe-exceptions+++test-suite test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Tasty.hs+  default-language:    Haskell2010+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -Wall -Wunused-top-binds+  other-modules:       Control.Exception.ThrowableTest+  build-depends:       base+                     , either+                     , safe-exceptions+                     , tasty+                     , tasty-discover+                     , tasty-hunit+                     , text+                     , throwable-exceptions