import PrelAddr
import PrelPack ( unpackCString )
import PrelBase
-import PrelArr ( ByteArray(..), MutableVar(..) )
+import PrelArr ( ByteArray(..), MutableVar )
import PrelGHC
\end{code}
explicitly mentioned in the standard, any descriptive string may be
used.
-\begin{change}
-SOF & 4/96 & added argument to indicate function that flagged error
-\end{change}
-% Hmm..does these envs work?!...SOF
-
\begin{code}
constructErrorAndFail :: String -> IO a
constructErrorAndFail call_site
= constructError call_site >>= \ io_error ->
fail io_error
+constructErrorAndFailWithInfo :: String -> String -> IO a
+constructErrorAndFailWithInfo call_site reason
+ = constructErrorMsg call_site (Just reason) >>= \ io_error ->
+ fail io_error
+
\end{code}
This doesn't seem to be documented/spelled out anywhere,
\begin{code}
constructError :: String -> IO IOError
-constructError call_site =
+constructError call_site = constructErrorMsg call_site Nothing
+
+constructErrorMsg :: String -> Maybe String -> IO IOError
+constructErrorMsg call_site reason =
_casm_ ``%r = ghc_errtype;'' >>= \ (I# errtype#) ->
_casm_ ``%r = ghc_errstr;'' >>= \ str ->
let
msg =
call_site ++ ':' : ' ' : unpackCString str ++
- case iot of
+ (case iot of
OtherError -> "(error code: " ++ show (I# errtype#) ++ ")"
- _ -> ""
+ _ -> "") ++
+ (case reason of
+ Nothing -> ""
+ Just m -> ' ':m)
in
return (IOError Nothing iot msg)
\end{code}