2 % (c) The GRASP Project, Glasgow University, 1992-2000
4 \section{Panic error messages}
6 Defines basic funtions for printing error messages.
8 It's hard to put these functions anywhere else without causing
9 some unnecessary loops in the module dependency graph.
14 GhcException(..), ghcError, progName,
15 panic, panic#, assertPanic, trace
25 #include "HsVersions.h"
28 GHC's own exception type.
31 ghcError :: GhcException -> a
32 ghcError e = throwDyn e
35 = PhaseFailed String ExitCode
37 | UsageError String -- prints the short usage msg after the error
38 | Panic String -- the `impossible' happened
39 | OtherError String -- just prints the error message
42 progName = unsafePerformIO (getProgName)
43 {-# NOINLINE progName #-}
45 short_usage = "Usage: For basic information, try the `--help' option."
47 instance Show GhcException where
48 showsPrec _ e = showString progName . showString ": " . showBarf e
50 showBarf (UsageError str)
51 = showString str . showChar '\n' . showString short_usage
52 showBarf (OtherError str)
54 showBarf (PhaseFailed phase code)
55 = showString phase . showString " failed, code = " . shows code
56 showBarf (Interrupted)
57 = showString "interrupted"
59 = showString ("panic! (the `impossible' happened):\n\t"
61 ++ "Please report it as a compiler bug "
62 ++ "to glasgow-haskell-bugs@haskell.org.\n\n")
64 ghcExceptionTc = mkTyCon "GhcException"
65 {-# NOINLINE ghcExceptionTc #-}
66 instance Typeable GhcException where
67 typeOf _ = mkAppTy ghcExceptionTc []
74 panic x = throwDyn (Panic x)
76 -- #-versions because panic can't return an unboxed int, and that's
77 -- what TAG_ is with GHC at the moment. Ugh. (Simon)
78 -- No, man -- Too Beautiful! (Will)
80 panic# :: String -> FastInt
81 panic# s = case (panic s) of () -> _ILIT 0
83 assertPanic :: String -> Int -> a
84 assertPanic file line =
85 throw (AssertionFailed
86 ("ASSERT failed! file " ++ file ++ ", line " ++ show line))