2 % (c) The AQUA Project, Glasgow University, 1994-1997
5 \section[PrelMain]{Module @PrelMain@}
8 {-# OPTIONS -#include "cbits/stgio.h" #-}
10 module PrelMain( mainIO ) where
13 import {-# SOURCE #-} qualified Main -- for type of "Main.main"
14 import IO ( hFlush, hPutStr, stdout, stderr )
15 import PrelAddr ( Addr )
17 import PrelPack ( packString )
18 import PrelArr ( ByteArray(..) )
22 mainIO :: IO () -- It must be of type (IO t) because that's what
23 -- the RTS expects. GHC doesn't check this, so
24 -- make sure this type signature stays!
25 mainIO = catchException Main.main handler
27 -- make sure we handle errors while reporting the error!
28 -- (e.g. evaluating the string passed to 'error' might generate
29 -- another error, etc.)
31 handler :: Exception -> IO ()
32 handler err = catchException (real_handler err) handler
34 real_handler :: Exception -> IO ()
37 ErrorCall s -> reportError s
38 other -> reportError (showsPrec 0 other "\n")
40 reportError :: String -> IO ()
42 (hFlush stdout) `catchException` (\ _ -> return ())
43 let bs@(ByteArray (_,len) _) = packString str
44 _ccall_ writeErrString__ (``&ErrorHdrHook''::Addr) bs len
45 _ccall_ stg_exit (1::Int)