blob: 753fa894b61f43ebbb47c0baa86f6e5cc222748b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
module Main where
import Control.Concurrent
import Control.Exception
--import GlaExts
data Result = Died SomeException | Finished
-- Test stack overflow catching. Should print "Died: stack overflow".
stackoverflow :: Int -> Int
stackoverflow 0 = 1
stackoverflow n = n + stackoverflow n
main = do
let x = stackoverflow 1
result <- newEmptyMVar
forkIO $ Control.Exception.catch (evaluate x >> putMVar result Finished) $
\e -> putMVar result (Died e)
res <- takeMVar result
case res of
Died e -> putStr ("Died: " ++ show e ++ "\n")
Finished -> putStr "Ok.\n"
|