1 -- -----------------------------------------------------------------------------
2 -- $Id: PrelTopHandler.lhs,v 1.1 2001/05/21 14:07:31 simonmar Exp $
4 -- (c) The University of Glasgow, 2001
8 -- 'Top-level' IO actions want to catch exceptions (e.g., forkIO and
9 -- PrelMain.mainIO) and report them - topHandler is the exception
10 -- handler they should use for this:
12 -- make sure we handle errors while reporting the error!
13 -- (e.g. evaluating the string passed to 'error' might generate
14 -- another error, etc.)
16 -- These functions can't go in PrelMain, because PrelMain isn't
17 -- included in HSstd.o (because PrelMain depends on Main, which
18 -- doesn't exist yet...).
21 module PrelTopHandler (
22 topHandler, reportStackOverflow, reportError
32 topHandler :: Exception -> IO ()
33 topHandler err = catchException (real_handler err) topHandler
35 real_handler :: Exception -> IO ()
38 AsyncException StackOverflow -> reportStackOverflow True
39 ErrorCall s -> reportError True s
40 other -> reportError True (showsPrec 0 other "\n")
42 reportStackOverflow :: Bool -> IO ()
43 reportStackOverflow bombOut = do
44 (hFlush stdout) `catchException` (\ _ -> return ())
51 reportError :: Bool -> String -> IO ()
52 reportError bombOut str = do
53 (hFlush stdout) `catchException` (\ _ -> return ())
54 withCStringLen str $ \(cstr,len) -> do
55 writeErrString addrOf_ErrorHdrHook cstr len
60 foreign import ccall "addrOf_ErrorHdrHook" unsafe
61 addrOf_ErrorHdrHook :: Ptr ()
63 foreign import ccall "writeErrString__" unsafe
64 writeErrString :: Ptr () -> CString -> Int -> IO ()
66 -- SUP: Are the hooks allowed to re-enter Haskell land? If so, remove
68 foreign import ccall "stackOverflow" unsafe
69 callStackOverflowHook :: IO ()
71 foreign import ccall "stg_exit" unsafe
72 stg_exit :: Int -> IO ()