7 data Result = Died Exception | Finished
9 -- Test stack overflow catching. Should print "Died: stack overflow".
11 stackoverflow :: Int -> Int
13 stackoverflow n = n + stackoverflow n
16 let x = stackoverflow 1
17 result <- newEmptyMVar
18 forkIO (catchAllIO (x `seq` putMVar result Finished)
19 (\e -> putMVar result (Died e)))
20 res <- takeMVar result
22 Died e -> putStr ("Died: " ++ show e ++ "\n")
23 Finished -> putStr "Ok.\n"