From 271884f9b31cb0104a81a395e1cca75669fe4348 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sat, 2 Aug 2008 23:13:58 +0000 Subject: [PATCH] Remove the dangerous Exception functions 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 | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Control/Exception.hs b/Control/Exception.hs index 5409211..e8032b7 100644 --- a/Control/Exception.hs +++ b/Control/Exception.hs @@ -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 ) -- ----------------------------------------------------------------------------- -- 1.7.10.4