summaryrefslogtreecommitdiff
path: root/Utility/Exception.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-27 00:42:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-27 00:42:14 -0400
commitce5b38aa1dbd1e320c5247d95344e373bf03e7cf (patch)
tree99e55c492457520f016188e00ba553c23f8bc187 /Utility/Exception.hs
parent5b7d00b6e9f79f4e0a2093feea58ad164a766ab2 (diff)
reconnect XMPP when NetWatcher notices a change
Diffstat (limited to 'Utility/Exception.hs')
-rw-r--r--Utility/Exception.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/Utility/Exception.hs b/Utility/Exception.hs
index 8b6077743..45f2aecec 100644
--- a/Utility/Exception.hs
+++ b/Utility/Exception.hs
@@ -1,10 +1,12 @@
-{- Simple IO exception handling
+{- Simple IO exception handling (and some more)
-
- Copyright 2011-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE ScopedTypeVariables #-}
+
module Utility.Exception where
import Prelude hiding (catch)
@@ -34,3 +36,16 @@ catchIO = catch
{- try specialized for IO errors only -}
tryIO :: IO a -> IO (Either IOException a)
tryIO = try
+
+{- Catches all exceptions except for async exceptions.
+ - This is often better to use than catching them all, so that
+ - ThreadKilled and UserInterrupt get through.
+ -}
+catchNonAsync :: IO a -> (SomeException -> IO a) -> IO a
+catchNonAsync a onerr = a `catches`
+ [ Handler (\ (e :: AsyncException) -> throw e)
+ , Handler (\ (e :: SomeException) -> onerr e)
+ ]
+
+tryNonAsync :: IO a -> IO (Either SomeException a)
+tryNonAsync a = (Right <$> a) `catchNonAsync` (return . Left)