Put in some parens to clarify how things parse
[ghc-base.git] / Control / Exception.hs
index c49b6b8..13b6cac 100644 (file)
@@ -1,4 +1,7 @@
 {-# OPTIONS_GHC -XNoImplicitPrelude #-}
+
+#include "Typeable.h"
+
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  Control.Exception
@@ -46,6 +49,7 @@ module Control.Exception (
         RecConError(..),
         RecSelError(..),
         RecUpdError(..),
+        ErrorCall(..),
 
         -- * Throwing exceptions
         throwIO,        -- :: Exception -> IO a
@@ -76,6 +80,7 @@ module Control.Exception (
         try,       -- :: IO a -> IO (Either Exception a)
         tryJust,   -- :: (Exception -> Maybe b) -> a    -> IO (Either b a)
         ignoreExceptions,
+        onException,
 
         -- ** The @evaluate@ function
         evaluate,  -- :: a -> IO a
@@ -127,6 +132,7 @@ module Control.Exception (
 
 #ifdef __GLASGOW_HASKELL__
 import GHC.Base
+import GHC.IOBase
 import {-# SOURCE #-} GHC.Handle
 import GHC.List
 import GHC.Num
@@ -347,6 +353,10 @@ tryJust p a = do
 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)
+
 -----------------------------------------------------------------------------
 -- Some Useful Functions
 
@@ -551,7 +561,7 @@ patError                 s = throw (PatternMatchFail (untangle s "Non-exhaustive
 -----
 
 data PatternMatchFail = PatternMatchFail String
-    deriving Typeable
+INSTANCE_TYPEABLE0(PatternMatchFail,patternMatchFailTc,"PatternMatchFail")
 
 instance Exception PatternMatchFail
 
@@ -561,7 +571,7 @@ instance Show PatternMatchFail where
 -----
 
 data RecSelError = RecSelError String
-    deriving Typeable
+INSTANCE_TYPEABLE0(RecSelError,recSelErrorTc,"RecSelError")
 
 instance Exception RecSelError
 
@@ -571,7 +581,7 @@ instance Show RecSelError where
 -----
 
 data RecConError = RecConError String
-    deriving Typeable
+INSTANCE_TYPEABLE0(RecConError,recConErrorTc,"RecConError")
 
 instance Exception RecConError
 
@@ -581,7 +591,7 @@ instance Show RecConError where
 -----
 
 data RecUpdError = RecUpdError String
-    deriving Typeable
+INSTANCE_TYPEABLE0(RecUpdError,recUpdErrorTc,"RecUpdError")
 
 instance Exception RecUpdError
 
@@ -591,7 +601,7 @@ instance Show RecUpdError where
 -----
 
 data NoMethodError = NoMethodError String
-    deriving Typeable
+INSTANCE_TYPEABLE0(NoMethodError,noMethodErrorTc,"NoMethodError")
 
 instance Exception NoMethodError
 
@@ -601,7 +611,7 @@ instance Show NoMethodError where
 -----
 
 data AssertionFailed = AssertionFailed String
-    deriving Typeable
+INSTANCE_TYPEABLE0(AssertionFailed,assertionFailedTc,"AssertionFailed")
 
 instance Exception AssertionFailed
 
@@ -611,7 +621,7 @@ instance Show AssertionFailed where
 -----
 
 data NonTermination = NonTermination
-    deriving Typeable
+INSTANCE_TYPEABLE0(NonTermination,nonTerminationTc,"NonTermination")
 
 instance Exception NonTermination
 
@@ -625,7 +635,7 @@ nonTermination = toException NonTermination
 -----
 
 data Deadlock = Deadlock
-    deriving Typeable
+INSTANCE_TYPEABLE0(Deadlock,deadlockTc,"Deadlock")
 
 instance Exception Deadlock
 
@@ -635,7 +645,7 @@ instance Show Deadlock where
 -----
 
 data NestedAtomically = NestedAtomically
-    deriving Typeable
+INSTANCE_TYPEABLE0(NestedAtomically,nestedAtomicallyTc,"NestedAtomically")
 
 instance Exception NestedAtomically