[project @ 2001-05-18 14:18:34 by simonmar]
[ghc-hetmet.git] / ghc / tests / lib / should_run / exceptions001.hs
index fa38c0f..e585ca5 100644 (file)
@@ -1,7 +1,7 @@
 module Main where
 
 import Prelude hiding (catch)
-import Exception
+import Exception 
 import IO hiding (try, catch)
 
 main = do
@@ -13,23 +13,22 @@ 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 = getException (1 + error "call to 'error'") >>= \r ->
+errorTest = try (evaluate (1 + error "call to 'error'")) >>= \r ->
            case r of
-               Just exception -> putStr "error call caught\n"
-               Nothing        -> error "help!"
+               Left exception -> putStr "error call caught\n"
+               Right _        -> error "help!"
 
 instance (Show a, Eq a) => Num (Maybe a) where {}
 
 noMethodTest :: IO ()
-noMethodTest = getException (Just () + Just ()) >>= \ r ->
+noMethodTest = try (evaluate (Just () + Just ())) >>= \ r ->
        case r of
-               Just (NoMethodError err) -> putStr "no method error\n"
-               other                    -> error "help!"
+               Left (NoMethodError err) -> putStr "no method error\n"
+               Right _                  -> error "help!"
 
 patMatchTest :: IO ()
 patMatchTest = catch (case test1 [1..10] of () -> return ())
@@ -41,7 +40,7 @@ test1 [] = ()
 
 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] = ()