X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FErr.lhs;h=90142f400ff76b775eb2f5550cf26380adbda4c9;hb=41e8fba828acbae1751628af50849f5352b27873;hp=43834aa5698b3000ed2de7e9582e05ae7425d20c;hpb=3d2db48412b8f469ba4943f95b0dce9354de4afb;p=ghc-base.git diff --git a/GHC/Err.lhs b/GHC/Err.lhs index 43834aa..90142f4 100644 --- a/GHC/Err.lhs +++ b/GHC/Err.lhs @@ -1,5 +1,7 @@ \begin{code} -{-# OPTIONS -fno-implicit-prelude #-} +{-# LANGUAGE CPP, NoImplicitPrelude #-} +{-# OPTIONS_HADDOCK hide #-} + ----------------------------------------------------------------------------- -- | -- Module : GHC.Err @@ -19,44 +21,38 @@ -- ----------------------------------------------------------------------------- -module GHC.Err +-- #hide +module GHC.Err ( - irrefutPatError - , noMethodBindingError - , nonExhaustiveGuardsError - , patError - , recSelError - , recConError - , runtimeError -- :: Addr# -> a -- Addr# points to UTF8 encoded C string - - , absentErr -- :: a - - , error -- :: String -> a - , assertError -- :: String -> Bool -> a -> a - - , undefined -- :: a + absentErr -- :: a + , divZeroError -- :: a + , overflowError -- :: a + + , error -- :: String -> a + + , undefined -- :: a ) where #ifndef __HADDOCK__ -import GHC.Base -import GHC.List ( span ) +import GHC.Types import GHC.Exception #endif \end{code} %********************************************************* -%* * +%* * \subsection{Error-ish functions} -%* * +%* * %********************************************************* \begin{code} --- error stops execution and displays an error message -error :: String -> a +-- | 'error' stops execution and displays an error message. +error :: [Char] -> a error s = throw (ErrorCall s) +-- | A special case of 'error'. -- It is expected that compilers will recognize this and insert error --- messages which are more appropriate to the context in which undefined +-- messages which are more appropriate to the context in which 'undefined' -- appears. undefined :: a @@ -64,9 +60,9 @@ undefined = error "Prelude.undefined" \end{code} %********************************************************* -%* * +%* * \subsection{Compiler generated errors + local utils} -%* * +%* * %********************************************************* Used for compiler-generated error message; @@ -78,51 +74,17 @@ absentErr :: a absentErr = error "Oops! The program has entered an `absent' argument!\n" \end{code} -\begin{code} -recSelError, recConError, irrefutPatError, runtimeError, - nonExhaustiveGuardsError, patError, noMethodBindingError - :: Addr# -> a -- All take a UTF8-encoded C string - -recSelError s = throw (RecSelError (unpackCStringUtf8# s)) -- No location info unfortunately -runtimeError s = error (unpackCStringUtf8# s) -- No location info unfortunately - -nonExhaustiveGuardsError s = throw (PatternMatchFail (untangle s "Non-exhaustive guards in")) -irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern")) -recConError s = throw (RecConError (untangle s "Missing field in record construction")) -noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation")) -patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in")) - -assertError :: Addr# -> Bool -> a -> a -assertError str pred v - | pred = v - | otherwise = throw (AssertionFailed (untangle str "Assertion failed")) -\end{code} - - -(untangle coded message) expects "coded" to be of the form - - "location|details" - -It prints - - location message details +Divide by zero and arithmetic overflow. +We put them here because they are needed relatively early +in the libraries before the Exception type has been defined yet. \begin{code} -untangle :: Addr# -> String -> String -untangle coded message - = location - ++ ": " - ++ message - ++ details - ++ "\n" - where - coded_str = unpackCStringUtf8# coded - - (location, details) - = case (span not_bar coded_str) of { (loc, rest) -> - case rest of - ('|':det) -> (loc, ' ' : det) - _ -> (loc, "") - } - not_bar c = c /= '|' +{-# NOINLINE divZeroError #-} +divZeroError :: a +divZeroError = throw DivideByZero + +{-# NOINLINE overflowError #-} +overflowError :: a +overflowError = throw Overflow \end{code} +