X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FErr.lhs;h=85453aa11d6e8c923357ff2c9a8e9d91cada4a21;hb=d9a0d6f44a930da4ae49678908e37793d693467c;hp=d3596ff80f25c041141b55c335e6bd20e7257902;hpb=e1550f94be21fa41bbc7bd13e19220d213133d9f;p=ghc-base.git diff --git a/GHC/Err.lhs b/GHC/Err.lhs index d3596ff..85453aa 100644 --- a/GHC/Err.lhs +++ b/GHC/Err.lhs @@ -1,20 +1,25 @@ -% ----------------------------------------------------------------------------- -% $Id: Err.lhs,v 1.2 2001/07/31 13:11:07 simonmar Exp $ -% -% (c) The University of Glasgow, 1994-2000 -% - -\section[GHC.Err]{Module @GHC.Err@} - -The GHC.Err module defines the code for the wired-in error functions, -which have a special type in the compiler (with "open tyvars"). - -We cannot define these functions in a module where they might be used -(e.g., GHC.Base), because the magical wired-in type will get confused -with what the typechecker figures out. - \begin{code} -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} +----------------------------------------------------------------------------- +-- | +-- Module : GHC.Err +-- Copyright : (c) The University of Glasgow, 1994-2002 +-- License : see libraries/base/LICENSE +-- +-- Maintainer : cvs-ghc@haskell.org +-- Stability : internal +-- Portability : non-portable (GHC extensions) +-- +-- The "GHC.Err" module defines the code for the wired-in error functions, +-- which have a special type in the compiler (with \"open tyvars\"). +-- +-- We cannot define these functions in a module where they might be used +-- (e.g., "GHC.Base"), because the magical wired-in type will get confused +-- with what the typechecker figures out. +-- +----------------------------------------------------------------------------- + +-- #hide module GHC.Err ( irrefutPatError @@ -23,21 +28,22 @@ module GHC.Err , patError , recSelError , recConError - , recUpdError -- :: String -> a + , runtimeError -- :: Addr# -> a -- Addr# points to UTF8 encoded C string - , absentErr, parError -- :: a - , seqError -- :: a + , absentErr -- :: a + , divZeroError -- :: a - , errorCString -- :: Addr# -> a -- Arg is a ptr to C string , error -- :: String -> a , assertError -- :: String -> Bool -> a -> a , undefined -- :: a ) where +#ifndef __HADDOCK__ import GHC.Base import GHC.List ( span ) import GHC.Exception +#endif \end{code} %********************************************************* @@ -47,15 +53,13 @@ import GHC.Exception %********************************************************* \begin{code} --- error stops execution and displays an error message +-- | 'error' stops execution and displays an error message. error :: String -> a error s = throw (ErrorCall s) -errorCString :: Addr# -> a -errorCString s = error (unpackCString 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 @@ -72,37 +76,29 @@ Used for compiler-generated error message; encoding saves bytes of string junk. \begin{code} -absentErr, parError, seqError :: a +absentErr :: a absentErr = error "Oops! The program has entered an `absent' argument!\n" -parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n" -seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n" - \end{code} \begin{code} -irrefutPatError - , noMethodBindingError - , nonExhaustiveGuardsError - , patError - , recSelError - , recConError - , recUpdError :: String -> a - -noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation")) -irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern")) +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")) -recSelError s = throw (RecSelError (untangle s "Missing field in record selection")) -recConError s = throw (RecConError (untangle s "Missing field in record construction")) -recUpdError s = throw (RecUpdError (untangle s "Record doesn't contain field(s) to be updated")) - -assertError :: String -> Bool -> a -> a +assertError :: Addr# -> Bool -> a -> a assertError str pred v | pred = v | otherwise = throw (AssertionFailed (untangle str "Assertion failed")) - \end{code} @@ -115,7 +111,7 @@ It prints location message details \begin{code} -untangle :: String -> String -> String +untangle :: Addr# -> String -> String untangle coded message = location ++ ": " @@ -123,11 +119,23 @@ untangle coded message ++ details ++ "\n" where + coded_str = unpackCStringUtf8# coded + (location, details) - = case (span not_bar coded) of { (loc, rest) -> + = case (span not_bar coded_str) of { (loc, rest) -> case rest of ('|':det) -> (loc, ' ' : det) _ -> (loc, "") } not_bar c = c /= '|' \end{code} + +Divide by zero. We put it here because it is needed relatively early +in the libraries before the Exception type has been defined yet. + +\begin{code} +{-# NOINLINE divZeroError #-} +divZeroError :: a +divZeroError = throw (ArithException DivideByZero) +\end{code} +