X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FException.hs;h=8a66e9710fccfd9e80465352dfd8234088a42f0a;hb=f7a485978f04e84b086f1974b88887cc72d832d0;hp=444ac876f6c146a779e1ad03c81a22e630363ad5;hpb=7f1f4e7a695c402ddd3a1dc2cc7114e649a78ebc;p=ghc-base.git diff --git a/Control/Exception.hs b/Control/Exception.hs index 444ac87..8a66e97 100644 --- a/Control/Exception.hs +++ b/Control/Exception.hs @@ -1,15 +1,13 @@ ----------------------------------------------------------------------------- --- +-- | -- Module : Control.Exception -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org -- Stability : experimental -- Portability : non-portable -- --- $Id: Exception.hs,v 1.1 2001/06/28 14:15:01 simonmar Exp $ --- -- The External API for exceptions. The functions provided in this -- module allow catching of exceptions in the IO monad. -- @@ -29,9 +27,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 @@ -44,10 +45,7 @@ module Control.Exception ( -- Throwing exceptions throw, -- :: Exception -> a -#ifndef __STGHUGS__ - -- for now throwTo, -- :: ThreadId -> Exception -> a -#endif -- Dynamic exceptions @@ -76,7 +74,8 @@ module Control.Exception ( #ifdef __GLASGOW_HASKELL__ import Prelude hiding (catch) -import GHC.Prim ( assert ) +import System.IO.Error +import GHC.Base ( assert ) import GHC.Exception hiding (try, catch, bracket, bracket_) import GHC.Conc ( throwTo, ThreadId ) import GHC.IOBase ( IO(..) ) @@ -105,10 +104,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 +115,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 @@ -193,7 +198,7 @@ dynExceptions _ = Nothing asyncExceptions (AsyncException e) = Just e asyncExceptions _ = Nothing -userErrors (UserError e) = Just e +userErrors e | isUserError e = Just (ioeGetErrorString e) userErrors _ = Nothing -----------------------------------------------------------------------------