% ------------------------------------------------------------------------------
-% $Id: PrelHandle.lhs,v 1.63 2000/11/07 10:42:56 simonmar Exp $
+% $Id: PrelHandle.lhs,v 1.64 2001/01/10 16:28:15 qrczak Exp $
%
% (c) The AQUA Project, Glasgow University, 1994-2000
%
import PrelAddr ( Addr, nullAddr )
import PrelByteArr ( ByteArray(..) )
import PrelRead ( Read )
-import PrelList ( span )
+import PrelList ( break )
import PrelIOBase
import PrelMaybe ( Maybe(..) )
import PrelException
ioeGetErrorString :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
-ioeGetHandle (IOException (IOError h _ _ _)) = h
-ioeGetHandle _ = error "IO.ioeGetHandle: not an IO error"
+ioeGetHandle (IOException (IOError h _ _ _)) = h
+ioeGetHandle (UserError _) = Nothing
+ioeGetHandle _ = error "IO.ioeGetHandle: not an IO error"
ioeGetErrorString (IOException (IOError _ iot _ str)) =
- case iot of
- EOF -> "end of file"
- _ -> str
-ioeGetErrorString _ = error "IO.ioeGetErrorString: not an IO error"
+ case iot of
+ EOF -> "end of file"
+ _ -> str
+ioeGetErrorString (UserError str) = str
+ioeGetErrorString _ = error "IO.ioeGetErrorString: not an IO error"
ioeGetFileName (IOException (IOError _ _ _ str)) =
- case span (/=':') str of
- (_,[]) -> Nothing
- (fs,_) -> Just fs
-ioeGetFileName _ = error "IO.ioeGetFileName: not an IO error"
+ case break (== ':') str of
+ (_, []) -> Nothing
+ (_, _:' ':fs)-> Just fs
+ioeGetFileName (UserError _) = Nothing
+ioeGetFileName _ = error "IO.ioeGetFileName: not an IO error"
\end{code}
'Top-level' IO actions want to catch exceptions (e.g., forkIO and
% ------------------------------------------------------------------------------
-% $Id: PrelIOBase.lhs,v 1.29 2000/11/07 10:42:56 simonmar Exp $
+% $Id: PrelIOBase.lhs,v 1.30 2001/01/10 16:28:15 qrczak Exp $
%
% (c) The University of Glasgow, 1994-2000
%
return x = returnIO x
m >>= k = bindIO m k
- fail s = error s -- not ioError?
+ fail s = ioError (userError s)
liftIO :: IO a -> State# RealWorld -> STret RealWorld a
liftIO (IO m) = \s -> case m s of (# s', r #) -> STret s' r
ERR_RESOURCEVANISHED -> ResourceVanished
ERR_SYSTEMERROR -> SystemError
ERR_TIMEEXPIRED -> TimeExpired
- ERR_UNSATISFIEDCONSTRAINTS -> UnsatisfiedConstraints
- ERR_UNSUPPORTEDOPERATION -> UnsupportedOperation
+ ERR_UNSATISFIEDCONSTRAINTS -> UnsatisfiedConstraints
+ ERR_UNSUPPORTEDOPERATION -> UnsupportedOperation
ERR_EOF -> EOF
_ -> OtherError
_ -> "") ++
(case reason of
Nothing -> ""
- Just m -> ' ':m)
+ Just m -> ": "++m)
in
return (IOError Nothing iot call_site msg)
\end{code}