From 79fabc70edc20a9f4e888e993c66bdc4236e8612 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 31 Jul 2001 14:34:23 +0000 Subject: [PATCH] [project @ 2001-07-31 14:34:23 by simonmar] add a couple of useful variants of catch & catchJust: handle :: (Exception -> IO a) -> IO a -> IO a handleJust :: (Exception -> Maybe b) -> (b -> IO a) -> IO a -> IO a --- Control/Exception.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Control/Exception.hs b/Control/Exception.hs index 444ac87..041b222 100644 --- a/Control/Exception.hs +++ b/Control/Exception.hs @@ -8,7 +8,7 @@ -- Stability : experimental -- Portability : non-portable -- --- $Id: Exception.hs,v 1.1 2001/06/28 14:15:01 simonmar Exp $ +-- $Id: Exception.hs,v 1.2 2001/07/31 14:34:23 simonmar Exp $ -- -- The External API for exceptions. The functions provided in this -- module allow catching of exceptions in the IO monad. @@ -29,9 +29,12 @@ module Control.Exception ( catch, -- :: IO a -> (Exception -> IO a) -> IO a catchJust, -- :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a + handle, -- :: (Exception -> IO a) -> IO a -> IO a + handleJust,-- :: (Exception -> Maybe b) -> (b -> IO a) -> IO a -> IO a + evaluate, -- :: a -> IO a - -- Exception predicates (for catchJust, tryJust) + -- Exception predicates (for tryJust, catchJust, handleJust) ioErrors, -- :: Exception -> Maybe IOError arithExceptions, -- :: Exception -> Maybe ArithException @@ -105,10 +108,10 @@ INSTANCE_TYPEABLE0(AsyncException,asyncExceptionTc,"AsyncException") ----------------------------------------------------------------------------- -- Catching exceptions --- PrelException defines 'catchException' for us. +-- GHC.Exception defines 'catchException' for us. -catch :: IO a -> (Exception -> IO a) -> IO a -catch = catchException +catch :: IO a -> (Exception -> IO a) -> IO a +catch = catchException catchJust :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a catchJust p a handler = catch a handler' @@ -116,6 +119,12 @@ catchJust p a handler = catch a handler' Nothing -> throw e Just b -> handler b +handle :: (Exception -> IO a) -> IO a -> IO a +handle = flip catch + +handleJust :: (Exception -> Maybe b) -> (b -> IO a) -> IO a -> IO a +handleJust p = flip (catchJust p) + ----------------------------------------------------------------------------- -- evaluate -- 1.7.10.4