add some more exception handling primitives
This commit is contained in:
parent
867fd116a7
commit
7496355031
1 changed files with 14 additions and 1 deletions
|
@ -5,12 +5,13 @@
|
||||||
- AnnexState are retained. This works because the Annex monad
|
- AnnexState are retained. This works because the Annex monad
|
||||||
- internally stores the AnnexState in a MVar.
|
- internally stores the AnnexState in a MVar.
|
||||||
-
|
-
|
||||||
- Copyright 2011-2013 Joey Hess <joey@kitenet.net>
|
- Copyright 2011-2014 Joey Hess <joey@kitenet.net>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE PackageImports #-}
|
{-# LANGUAGE PackageImports #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
module Annex.Exception (
|
module Annex.Exception (
|
||||||
bracketIO,
|
bracketIO,
|
||||||
|
@ -19,6 +20,8 @@ module Annex.Exception (
|
||||||
tryAnnexIO,
|
tryAnnexIO,
|
||||||
throwAnnex,
|
throwAnnex,
|
||||||
catchAnnex,
|
catchAnnex,
|
||||||
|
catchNonAsyncAnnex,
|
||||||
|
tryNonAsyncAnnex,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Control.Monad.Catch as M
|
import qualified Control.Monad.Catch as M
|
||||||
|
@ -48,3 +51,13 @@ throwAnnex = M.throwM
|
||||||
{- catch in the Annex monad -}
|
{- catch in the Annex monad -}
|
||||||
catchAnnex :: Exception e => Annex a -> (e -> Annex a) -> Annex a
|
catchAnnex :: Exception e => Annex a -> (e -> Annex a) -> Annex a
|
||||||
catchAnnex = M.catch
|
catchAnnex = M.catch
|
||||||
|
|
||||||
|
{- catchs all exceptions except for async exceptions -}
|
||||||
|
catchNonAsyncAnnex :: Annex a -> (SomeException -> Annex a) -> Annex a
|
||||||
|
catchNonAsyncAnnex a onerr = a `M.catches`
|
||||||
|
[ M.Handler (\ (e :: AsyncException) -> throwAnnex e)
|
||||||
|
, M.Handler (\ (e :: SomeException) -> onerr e)
|
||||||
|
]
|
||||||
|
|
||||||
|
tryNonAsyncAnnex :: Annex a -> Annex (Either SomeException a)
|
||||||
|
tryNonAsyncAnnex a = (Right <$> a) `catchNonAsyncAnnex` (return . Left)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue