summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/lib/should_run/exceptionsrun001.hs
blob: 9c6febc049e78b4173ac93dea3e27ef965631fb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Main where

import Prelude hiding (catch)
import Control.OldException 

main = do
  ioTest
  errorTest
  noMethodTest
  patMatchTest
  guardTest
  dynTest

ioTest :: IO ()
ioTest = catchJust userErrors (ioError (userError "wibble")) 
	   (\ex -> putStr "user exception caught\n")

errorTest :: IO ()
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 = try (evaluate (Just () + Just ())) >>= \ r ->
	case r of
		Left (NoMethodError err) -> putStr "no method error\n"
		Right _                  -> error "help!"

patMatchTest :: IO ()
patMatchTest = catch (case test1 [1..10] of () -> return ())
  (\ex -> case ex of
		PatternMatchFail err -> putStr err
		other 		     -> error "help!")
		  
test1 [] = ()

guardTest = catch (case test2 of () -> return ())
  (\ex -> case ex of
		PatternMatchFail err -> putStr err
		other 		     -> error "help!")

test2 | all (==0) [1] = ()

dynTest = catchDyn (case throwDyn (42::Int, (+1)::Int->Int) of () -> return ())
  (\(i,f) -> let x = f (i::Int) :: Int in putStr (show x))

{-
recSelTest
recConTest
recUpdTest
assertTest
arithTest
-}