[project @ 2001-05-18 14:18:34 by simonmar]
[ghc-hetmet.git] / ghc / tests / lib / should_run / exceptions001.hs
index 38411a8..e585ca5 100644 (file)
@@ -1,8 +1,8 @@
 module Main where
 
 import Prelude hiding (catch)
-import Exception
-import IO hiding (try)
+import Exception 
+import IO hiding (try, catch)
 
 main = do
   ioTest
@@ -13,34 +13,34 @@ main = do
   dynTest
 
 ioTest :: IO ()
-ioTest = catchIO (fail (userError "wibble")) 
-          (\ex -> if isUserError ex then putStr "io exception caught\n" 
-                                    else error "help!")
+ioTest = catchJust userErrors (ioError (userError "wibble")) 
+          (\ex -> putStr "user exception caught\n")
 
 errorTest :: IO ()
-errorTest = case getExceptions (1 + error "call to 'error'") of
-               Left exceptions -> putStr "error call caught\n"
-               Right val       -> error "help!"
+errorTest = try (evaluate (1 + error "call to 'error'")) >>= \r ->
+           case r of
+               Left exception -> putStr "error call caught\n"
+               Right _        -> error "help!"
 
 instance (Show a, Eq a) => Num (Maybe a) where {}
 
 noMethodTest :: IO ()
-noMethodTest = catch (case Just () + Just () of Nothing -> return ())
-  (\exs -> case unsafePromiseSingleton exs of
-               NoMethodError err -> putStr "no method error\n"
-               other             -> error "help!")
+noMethodTest = try (evaluate (Just () + Just ())) >>= \ r ->
+       case r of
+               Left (NoMethodError err) -> putStr "no method error\n"
+               Right _                  -> error "help!"
 
 patMatchTest :: IO ()
-patMatchTest = catchOne (case test1 [1..10] of () -> return ())
+patMatchTest = catch (case test1 [1..10] of () -> return ())
   (\ex -> case ex of
                PatternMatchFail err -> putStr err
                other                -> error "help!")
                  
 test1 [] = ()
 
-guardTest = catchOne (case test2 of () -> return ())
+guardTest = catch (case test2 of () -> return ())
   (\ex -> case ex of
-               NonExhaustiveGuards err -> putStr err
+               PatternMatchFail err -> putStr err
                other                -> error "help!")
 
 test2 | all (==0) [1] = ()