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
26 #include "HsVersions.h"
29 GHC's own exception type.
32 ghcError :: GhcException -> a
33 ghcError e = throwDyn e
36 = PhaseFailed String ExitCode
38 | UsageError String -- prints the short usage msg after the error
39 | Panic String -- the `impossible' happened
40 | OtherError String -- just prints the error message
43 progName = unsafePerformIO (getProgName)
44 {-# NOINLINE progName #-}
46 short_usage = "Usage: For basic information, try the `--help' option."
48 instance Show GhcException where
49 showsPrec _ e = showString progName . showString ": " . showBarf e
51 showBarf (UsageError str)
52 = showString str . showChar '\n' . showString short_usage
53 showBarf (OtherError str)
55 showBarf (PhaseFailed phase code)
56 = showString phase . showString " failed, code = " . shows code
57 showBarf (Interrupted)
58 = showString "interrupted"
60 = showString ("panic! (the `impossible' happened, GHC version "
61 ++ cProjectVersion ++ "):\n\t"
63 ++ "Please report it as a compiler bug "
64 ++ "to glasgow-haskell-bugs@haskell.org.\n\n")
66 ghcExceptionTc = mkTyCon "GhcException"
67 {-# NOINLINE ghcExceptionTc #-}
68 instance Typeable GhcException where
69 typeOf _ = mkAppTy ghcExceptionTc []
76 panic x = throwDyn (Panic x)
78 -- #-versions because panic can't return an unboxed int, and that's
79 -- what TAG_ is with GHC at the moment. Ugh. (Simon)
80 -- No, man -- Too Beautiful! (Will)
82 panic# :: String -> FastInt
83 panic# s = case (panic s) of () -> _ILIT 0
85 assertPanic :: String -> Int -> a
86 assertPanic file line =
87 throw (AssertionFailed
88 ("ASSERT failed! file " ++ file ++ ", line " ++ show line))