Typo
[packages/base.git] / tests / exceptionsrun001.hs
1 module Main where
2
3 import Control.Exception
4 import System.IO.Error
5
6 main = do
7 ioTest
8 errorTest
9 noMethodTest
10 patMatchTest
11 guardTest
12
13 ioTest :: IO ()
14 ioTest = catchJust (\e -> if isUserError e then Just () else Nothing)
15 (ioError (userError "wibble"))
16 (\() -> putStrLn "user exception caught")
17
18 errorTest :: IO ()
19 errorTest = do r <- try (evaluate (1 + error "call to 'error'"))
20 case r of
21 Left (ErrorCall _) -> putStrLn "error call caught"
22 Right _ -> error "help!"
23
24 instance (Show a, Eq a) => Num (Maybe a) where {}
25
26 noMethodTest :: IO ()
27 noMethodTest = do r <- try (evaluate (Just () + Just ()))
28 case r of
29 Left (NoMethodError err) -> putStrLn "no method error"
30 Right _ -> error "help!"
31
32 patMatchTest :: IO ()
33 patMatchTest = catch (case test1 [1..10] of () -> return ())
34 (\ex -> case ex of
35 PatternMatchFail err -> putStr err
36 _ -> error "help!")
37
38 test1 [] = ()
39
40 guardTest = catch (case test2 of () -> return ())
41 (\ex -> case ex of
42 PatternMatchFail err -> putStr err
43 _ -> error "help!")
44
45 test2 | all (==0) [1] = ()
46