Remove the dangerous Exception functions
authorIan Lynagh <igloo@earth.li>
Sat, 2 Aug 2008 23:13:58 +0000 (23:13 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 2 Aug 2008 23:13:58 +0000 (23:13 +0000)
Removed: catchAny, handleAny, ignoreExceptions
These make it easy to eat /any/ exception, which is rarely what you want.
Normally you either want to:
* only catch exceptions in a certain part of the hierarchy, e.g.
  "file not found", in which case you should only catch exceptions
  of the appropriate type,
or
* you want to do some cleanup when an exception happens, and then rethrow
  the exception, in which case you should use onException, or one of the
  bracketing functions.

Control/Exception.hs

index 5409211..e8032b7 100644 (file)
@@ -68,18 +68,15 @@ module Control.Exception (
         -- ** The @catch@ functions
         catch,     -- :: IO a -> (Exception -> IO a) -> IO a
         catches, Handler(..),
-        catchAny,
         catchJust, -- :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a
 
         -- ** The @handle@ functions
         handle,    -- :: (Exception -> IO a) -> IO a -> IO a
-        handleAny,
         handleJust,-- :: (Exception -> Maybe b) -> (b -> IO a) -> IO a -> IO a
 
         -- ** The @try@ functions
         try,       -- :: IO a -> IO (Either Exception a)
         tryJust,   -- :: (Exception -> Maybe b) -> a    -> IO (Either b a)
-        ignoreExceptions,
         onException,
 
         -- ** The @evaluate@ function
@@ -290,9 +287,6 @@ catchJust p a handler = catch a handler'
 handle     :: Exception e => (e -> IO a) -> IO a -> IO a
 handle     =  flip catch
 
-handleAny  :: (forall e . Exception e => e -> IO a) -> IO a -> IO a
-handleAny  =  flip catchAny
-
 -- | A version of 'catchJust' with the arguments swapped around (see
 -- 'handle').
 handleJust :: Exception e => (e -> Maybe b) -> (b -> IO a) -> IO a -> IO a
@@ -343,9 +337,6 @@ tryJust p a = do
                         Nothing -> throw e
                         Just b  -> return (Left b)
 
-ignoreExceptions :: IO () -> IO ()
-ignoreExceptions io = io `catchAny` \_ -> return ()
-
 onException :: IO a -> IO () -> IO a
 onException io what = io `catch` \e -> do what
                                           throw (e :: SomeException)
@@ -381,9 +372,7 @@ bracket
 bracket before after thing =
   block (do
     a <- before 
-    r <- catchAny
-           (unblock (thing a))
-           (\e -> do { after a; throw e })
+    r <- unblock (thing a) `onException` after a
     after a
     return r
  )
@@ -398,9 +387,7 @@ finally :: IO a         -- ^ computation to run first
         -> IO a         -- returns the value from the first computation
 a `finally` sequel =
   block (do
-    r <- catchAny
-             (unblock a)
-             (\e -> do { sequel; throw e })
+    r <- unblock a `onException` sequel
     sequel
     return r
   )
@@ -420,9 +407,7 @@ bracketOnError
 bracketOnError before after thing =
   block (do
     a <- before 
-    catchAny
-        (unblock (thing a))
-        (\e -> do { after a; throw e })
+    unblock (thing a) `onException` after a
  )
 
 -- -----------------------------------------------------------------------------