- ExitException ExitSuccess -> safe_exit 0
- ExitException (ExitFailure n) -> safe_exit n
-
- Deadlock -> reportError True
- "no threads to run: infinite loop or deadlock?"
-
- ErrorCall s -> reportError True s
- other -> reportError True (showsPrec 0 other "\n")
-
-reportStackOverflow :: Bool -> IO a
-reportStackOverflow bombOut = do
- (hFlush stdout) `catchException` (\ _ -> return ())
- callStackOverflowHook
- if bombOut
- then exit 2
- else return undefined
-
-reportError :: Bool -> String -> IO a
-reportError bombOut str = do
- (hFlush stdout) `catchException` (\ _ -> return ())
- withCStringLen str $ \(cstr,len) -> do
- writeErrString errorHdrHook cstr len
- if bombOut
- then exit 1
- else return undefined
-
-#ifndef ILX
-foreign import ccall "&ErrorHdrHook" errorHdrHook :: Ptr ()
-#else
-foreign import ccall "ErrorHdrHook" errorHdrHook :: Ptr ()
-#endif
-
-foreign import ccall unsafe "writeErrString__"
- writeErrString :: Ptr () -> CString -> Int -> IO ()
+ ExitException ExitSuccess -> exit 0
+ ExitException (ExitFailure n) -> exit n
+
+ other -> do
+ reportError other
+ exit 1
+
+
+reportStackOverflow :: IO a
+reportStackOverflow = do callStackOverflowHook; return undefined
+
+reportError :: Exception -> IO a
+reportError ex = do
+ handler <- getUncaughtExceptionHandler
+ handler ex
+ return undefined