Commit 6151c960 authored by simonmar's avatar simonmar
Browse files

[project @ 2000-07-07 11:03:57 by simonmar]

Rearrange exception stuff, as per my message on glasgow-haskell-users
recently.

The main change is the IOError type is now a synonym for Exception.
IO.ioError can therefore be used for throwing exceptions.  IO.catch
still catches only IO exceptions, for backwards compatibility.

The interface exported by Exception has changed somewhat:

	try       :: IO a -> IO (Either Exception a)
	tryJust   :: (Exception -> Maybe b) -> a    -> IO (Either b a)

	catch     :: IO a -> (Exception -> IO a) -> IO a
	catchJust :: (Exception -> Maybe b) -> IO a -> (b -> IO a) -> IO a

	ioErrors		:: Exception -> Maybe IOError
	arithExceptions 	:: Exception -> Maybe ArithException
	errorCalls		:: Exception -> Maybe String
	dynExceptions		:: Exception -> Maybe Dynamic
	assertions		:: Exception -> Maybe String
	asyncExceptions 	:: Exception -> Maybe AsyncException

raiseInThread is now called throwTo.

Where possible, the old functions have been left around, but marked
deprecated.
parent 219fbecc
% -----------------------------------------------------------------------------
% $Id: CPUTime.lhs,v 1.24 2000/07/07 11:03:57 simonmar Exp $
%
% (c) The GRASP/AQUA Project, Glasgow University, 1995-1997
% (c) The University of Glasgow, 1995-2000
%
\section[CPUTime]{Haskell 1.4 CPU Time Library}
\section[CPUTime]{Haskell 98 CPU Time Library}
\begin{code}
{-# OPTIONS -#include "cbits/stgio.h" #-}
......@@ -23,8 +25,9 @@ import PrelBase ( Int(..) )
import PrelByteArr ( ByteArray(..), newIntArray )
import PrelArrExtra ( unsafeFreezeByteArray )
import PrelNum ( fromInt )
import PrelIOBase ( IOError(..), IOErrorType( UnsupportedOperation ),
unsafePerformIO, stToIO )
import PrelIOBase ( IOError(..), IOException(..),
IOErrorType( UnsupportedOperation ),
unsafePerformIO, stToIO, ioException )
import Ratio
\end{code}
......@@ -50,7 +53,7 @@ getCPUTime = do
fromIntegral (I# (indexIntArray# frozen# 2#)) * 1000000000 +
fromIntegral (I# (indexIntArray# frozen# 3#))) * 1000)
else
ioError (IOError Nothing UnsupportedOperation
ioException (IOError Nothing UnsupportedOperation
"getCPUTime"
"can't get CPU time")
......
% -----------------------------------------------------------------------------
% $Id: Directory.lhs,v 1.19 2000/07/07 11:03:57 simonmar Exp $
%
% (c) The AQUA Project, Glasgow University, 1994-1999
% (c) The University of Glasgow, 1994-2000
%
\section[Directory]{Directory interface}
A directory contains a series of entries, each of which is a named
......@@ -60,10 +63,10 @@ import PrelGHC ( RealWorld, or#, and# )
import PrelByteArr ( ByteArray, MutableByteArray,
newWordArray, readWordArray, newCharArray )
import PrelArrExtra ( unsafeFreezeByteArray )
import PrelPack ( unpackNBytesST, packString, unpackCStringST )
import PrelPack ( packString, unpackCStringST )
import PrelIOBase ( stToIO,
constructErrorAndFail, constructErrorAndFailWithInfo,
IOError(IOError), IOErrorType(SystemError) )
IOException(..), ioException, IOErrorType(SystemError) )
import Time ( ClockTime(..) )
import PrelAddr ( Addr, nullAddr, Word(..), wordToInt, intToWord )
#endif
......@@ -481,7 +484,7 @@ setPermissions name (Permissions r w e s) = do
rc <- primChmod (primPackString name) mode
if rc == 0
then return ()
else ioError (IOError Nothing SystemError "setPermissions" "insufficient permissions")
else ioException (IOError Nothing SystemError "setPermissions" "insufficient permissions")
\end{code}
(Sigh)..copied from Posix.Files to avoid dep. on posix library
......@@ -499,7 +502,7 @@ getFileStatus name = do
#else
then stToIO (unsafeFreezeByteArray bytes)
#endif
else ioError (IOError Nothing SystemError "getFileStatus" "")
else ioException (IOError Nothing SystemError "getFileStatus" "")
#ifndef __HUGS__
modificationTime :: FileStatus -> IO ClockTime
......
% -----------------------------------------------------------------------------
% $Id: PrelArr.lhs,v 1.23 2000/06/30 13:39:35 simonmar Exp $
% $Id: PrelArr.lhs,v 1.24 2000/07/07 11:03:57 simonmar Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -17,13 +17,10 @@ For byte-arrays see @PrelByteArr@.
module PrelArr where
import {-# SOURCE #-} PrelErr ( error )
import PrelList (foldl)
import PrelEnum
import PrelNum
import PrelST
import PrelBase
import PrelAddr
import PrelGHC
import PrelShow
infixl 9 !, //
......
% -----------------------------------------------------------------------------
% $Id: PrelBase.lhs,v 1.32 2000/06/30 13:39:35 simonmar Exp $
% $Id: PrelBase.lhs,v 1.33 2000/07/07 11:03:57 simonmar Exp $
%
% (c) The University of Glasgow, 1992-2000
%
......@@ -83,10 +83,6 @@ module PrelBase
)
where
import {-# SOURCE #-} PrelErr ( error )
import {-# SOURCE #-} PrelNum ( addr2Integer )
-- Otherwise the system import of addr2Integer looks for PrelNum.hi
import PrelGHC
infixr 9 .
......
% -----------------------------------------------------------------------------
% $Id: PrelByteArr.lhs,v 1.7 2000/06/30 13:39:35 simonmar Exp $
% $Id: PrelByteArr.lhs,v 1.8 2000/07/07 11:03:58 simonmar Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -16,11 +16,9 @@ module PrelByteArr where
import {-# SOURCE #-} PrelErr ( error )
import PrelArr
import PrelFloat
import PrelList (foldl)
import PrelST
import PrelBase
import PrelAddr
import PrelGHC
\end{code}
......
% -----------------------------------------------------------------------------
% $Id: PrelConc.lhs,v 1.20 2000/07/07 11:03:58 simonmar Exp $
%
% (c) The AQUA Project, Glasgow University, 1994-1996
% (c) The University of Glasgow, 1994-2000
%
\section[PrelConc]{Module @PrelConc@}
......@@ -15,7 +17,7 @@ module PrelConc
-- Forking and suchlike
, myThreadId -- :: IO ThreadId
, killThread -- :: ThreadId -> IO ()
, raiseInThread -- :: ThreadId -> Exception -> IO ()
, throwTo -- :: ThreadId -> Exception -> IO ()
, par -- :: a -> b -> b
, seq -- :: a -> b -> b
, yield -- :: IO ()
......@@ -41,8 +43,7 @@ module PrelConc
import PrelBase
import PrelMaybe
import PrelErr ( parError, seqError )
import PrelST ( liftST )
import PrelIOBase ( IO(..), MVar(..), unsafePerformIO )
import PrelIOBase ( IO(..), MVar(..) )
import PrelBase ( Int(..) )
import PrelException ( Exception(..), AsyncException(..) )
......@@ -67,8 +68,8 @@ killThread :: ThreadId -> IO ()
killThread (ThreadId id) = IO $ \ s ->
case (killThread# id (AsyncException ThreadKilled) s) of s1 -> (# s1, () #)
raiseInThread :: ThreadId -> Exception -> IO ()
raiseInThread (ThreadId id) ex = IO $ \ s ->
throwTo :: ThreadId -> Exception -> IO ()
throwTo (ThreadId id) ex = IO $ \ s ->
case (killThread# id ex s) of s1 -> (# s1, () #)
myThreadId :: IO ThreadId
......
---------------------------------------------------------------------------
-- PrelException.hi-boot
--
-- This hand-written interface file is the initial bootstrap version
-- for PrelException.hi.
---------------------------------------------------------------------------
__interface PrelException 1 where
__export PrelException ioError catch;
1 ioError :: __forall a => PrelIOBase.IOError -> PrelIOBase.IO a ;
1 catch :: __forall a => PrelIOBase.IO a -> (PrelIOBase.IOError -> PrelIOBase.IO a) -> PrelIOBase.IO a ; -- wish there could be more __o's here. KSW 1999-04.
% -----------------------------------------------------------------------------
% $Id: PrelException.lhs,v 1.21 2000/06/18 21:12:31 panne Exp $
% ------------------------------------------------------------------------------
% $Id: PrelException.lhs,v 1.22 2000/07/07 11:03:58 simonmar Exp $
%
% (c) The GRAP/AQUA Project, Glasgow University, 1998
% (c) The University of Glasgow, 1998-2000
%
Exceptions and exception-handling functions.
......@@ -10,122 +10,26 @@ Exceptions and exception-handling functions.
{-# OPTIONS -fno-implicit-prelude #-}
#ifndef __HUGS__
module PrelException where
module PrelException
( module PrelException,
Exception(..), AsyncException(..),
IOException(..), ArithException(..), ArrayException(..),
throw, ioError )
where
import PrelList
import PrelBase
import PrelMaybe
import PrelShow
import PrelIOBase
import PrelST ( STret(..) )
import PrelDynamic
import PrelGHC
#endif
\end{code}
%*********************************************************
%* *
\subsection{Exception datatype and operations}
%* *
%*********************************************************
\begin{code}
data Exception
= IOException IOError -- IO exceptions (from 'ioError')
| ArithException ArithException -- Arithmetic exceptions
| ArrayException ArrayException -- Array-related exceptions
| ErrorCall String -- Calls to 'error'
| NoMethodError String -- A non-existent method was invoked
| PatternMatchFail String -- A pattern match / guard failure
| RecSelError String -- Selecting a non-existent field
| RecConError String -- Field missing in record construction
| RecUpdError String -- Record doesn't contain updated field
| AssertionFailed String -- Assertions
| DynException Dynamic -- Dynamic exceptions
| AsyncException AsyncException -- Externally generated errors
| PutFullMVar -- Put on a full MVar
| BlockedOnDeadMVar -- Blocking on a dead MVar
| NonTermination
data ArithException
= Overflow
| Underflow
| LossOfPrecision
| DivideByZero
| Denormal
deriving (Eq, Ord)
data AsyncException
= StackOverflow
| HeapOverflow
| ThreadKilled
deriving (Eq, Ord)
data ArrayException
= IndexOutOfBounds String -- out-of-range array access
| UndefinedElement String -- evaluating an undefined element
deriving (Eq, Ord)
stackOverflow, heapOverflow :: Exception -- for the RTS
stackOverflow = AsyncException StackOverflow
heapOverflow = AsyncException HeapOverflow
instance Show ArithException where
showsPrec _ Overflow = showString "arithmetic overflow"
showsPrec _ Underflow = showString "arithmetic underflow"
showsPrec _ LossOfPrecision = showString "loss of precision"
showsPrec _ DivideByZero = showString "divide by zero"
showsPrec _ Denormal = showString "denormal"
instance Show AsyncException where
showsPrec _ StackOverflow = showString "stack overflow"
showsPrec _ HeapOverflow = showString "heap overflow"
showsPrec _ ThreadKilled = showString "thread killed"
instance Show ArrayException where
showsPrec _ (IndexOutOfBounds s)
= showString "array index out of range"
. (if not (null s) then showString ": " . showString s
else id)
showsPrec _ (UndefinedElement s)
= showString "undefined array element"
. (if not (null s) then showString ": " . showString s
else id)
instance Show Exception where
showsPrec _ (IOException err) = shows err
showsPrec _ (ArithException err) = shows err
showsPrec _ (ArrayException err) = shows err
showsPrec _ (ErrorCall err) = showString err
showsPrec _ (NoMethodError err) = showString err
showsPrec _ (PatternMatchFail err) = showString err
showsPrec _ (RecSelError err) = showString err
showsPrec _ (RecConError err) = showString err
showsPrec _ (RecUpdError err) = showString err
showsPrec _ (AssertionFailed err) = showString err
showsPrec _ (AsyncException e) = shows e
showsPrec _ (DynException _err) = showString "unknown exception"
showsPrec _ (PutFullMVar) = showString "putMVar: full MVar"
showsPrec _ (BlockedOnDeadMVar) = showString "thread blocked indefinitely"
showsPrec _ (NonTermination) = showString "<<loop>>"
#endif
\end{code}
%*********************************************************
%* *
\subsection{Primitive catch and throw}
\subsection{Primitive catch}
%* *
%*********************************************************
\begin{code}
throw :: Exception -> a
#ifdef __HUGS__
throw = primRaise
#else
throw exception = raise# exception
#endif
\end{code}
catchException used to handle the passing around of the state to the
action and the handler. This turned out to be a bad idea - it meant
that we had to wrap both arguments in thunks so they could be entered
......@@ -146,15 +50,10 @@ catchException m k = ST (\s -> unST m s `primCatch'` \ err -> unST (k err) s)
catchException (IO m) k = IO $ \s -> catch# m (\ex -> unIO (k ex)) s
#endif
catch :: IO a -> (IOError -> IO a) -> IO a
catch :: IO a -> (Exception -> IO a) -> IO a
catch m k = catchException m handler
where handler (IOException err) = k err
handler other = throw other
catchNonIO :: IO a -> (Exception -> IO a) -> IO a
catchNonIO m k = catchException m handler
where handler (IOException err) = ioError err
handler other = k other
where handler err@(IOException _) = k err
handler other = throw other
\end{code}
......@@ -167,8 +66,11 @@ catchNonIO m k = catchException m handler
The construct @try comp@ exposes errors which occur within a
computation, and which are not fully handled. It always succeeds.
These are the IO-only try/bracket. For the full exception try/bracket
see hslibs/lang/Exception.lhs.
\begin{code}
try :: IO a -> IO (Either IOError a)
try :: IO a -> IO (Either Exception a)
try f = catch (do r <- f
return (Right r))
(return . Left)
......@@ -194,22 +96,6 @@ bracket_ before after m = do
\end{code}
%*********************************************************
%* *
\subsection{ioError}
%* *
%*********************************************************
Why is this stuff here? To avoid recursive module dependencies of
course.
\begin{code}
ioError :: IOError -> IO a
ioError err = IO $ \s -> throw (IOException err) s
-- (ioError e) isn't an exception; we only throw
-- the exception when applied to a world
\end{code}
%*********************************************************
%* *
\subsection{Controlling asynchronous exception delivery}
......@@ -233,3 +119,4 @@ unblockAsyncExceptions (IO io) = IO io
#endif
\end{code}
% ------------------------------------------------------------------------------
% $Id: PrelHandle.lhs,v 1.59 2000/07/07 11:03:58 simonmar Exp $
%
% (c) The AQUA Project, Glasgow University, 1994-1996
% (c) The AQUA Project, Glasgow University, 1994-2000
%
\section[PrelHandle]{Module @PrelHandle@}
......@@ -17,12 +19,12 @@ module PrelHandle where
import PrelArr
import PrelBase
import PrelAddr ( Addr, nullAddr )
import PrelByteArr ( ByteArray(..), MutableByteArray(..) )
import PrelByteArr ( ByteArray(..) )
import PrelRead ( Read )
import PrelList ( span )
import PrelIOBase
import PrelException
import PrelMaybe ( Maybe(..) )
import PrelException
import PrelEnum
import PrelNum ( toBig, Integer(..), Num(..) )
import PrelShow
......@@ -53,6 +55,20 @@ import PrelForeign ( makeForeignObj, mkForeignObj )
#endif
\end{code}
\begin{code}
mkBuffer__ :: FILE_OBJECT -> Int -> IO ()
mkBuffer__ fo sz_in_bytes = do
chunk <-
case sz_in_bytes of
0 -> return nullAddr -- this has the effect of overwriting the pointer to the old buffer.
_ -> do
chunk <- allocMemory__ sz_in_bytes
if chunk == nullAddr
then ioException (IOError Nothing ResourceExhausted "mkBuffer__" "not enough virtual memory")
else return chunk
setBuf fo chunk sz_in_bytes
\end{code}
%*********************************************************
%* *
\subsection{Types @Handle@, @Handle__@}
......@@ -147,7 +163,7 @@ mkClosedHandle__ =
haBuffers__ = []
}
mkErrorHandle__ :: IOError -> Handle__
mkErrorHandle__ :: IOException -> Handle__
mkErrorHandle__ ioe =
Handle__ { haFO__ = nullFile__,
haType__ = (ErrorHandle ioe),
......@@ -379,7 +395,7 @@ hClose :: Handle -> IO ()
hClose handle =
withHandle__ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> return handle_
_ -> do
rc <- closeFile (haFO__ handle_)
......@@ -424,7 +440,7 @@ hFileSize :: Handle -> IO Integer
hFileSize handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hFileSize" handle
SemiClosedHandle -> ioe_closedHandle "hFileSize" handle
#ifdef __HUGS__
......@@ -515,15 +531,16 @@ hSetBuffering :: Handle -> BufferMode -> IO ()
hSetBuffering handle mode =
case mode of
BlockBuffering (Just n)
| n <= 0 -> ioError
| n <= 0 -> ioException
(IOError (Just handle)
InvalidArgument
"hSetBuffering"
("illegal buffer size " ++ showsPrec 9 n [])) -- 9 => should be parens'ified.
("illegal buffer size " ++ showsPrec 9 n []))
-- 9 => should be parens'ified.
_ ->
withHandle__ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hSetBuffering" handle
_ -> do
{- Note:
......@@ -697,7 +714,7 @@ hIsOpen :: Handle -> IO Bool
hIsOpen handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> return False
SemiClosedHandle -> return False
_ -> return True
......@@ -706,7 +723,7 @@ hIsClosed :: Handle -> IO Bool
hIsClosed handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> return True
_ -> return False
......@@ -724,7 +741,7 @@ hIsReadable :: Handle -> IO Bool
hIsReadable handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hIsReadable" handle
SemiClosedHandle -> ioe_closedHandle "hIsReadable" handle
htype -> return (isReadable htype)
......@@ -737,7 +754,7 @@ hIsWritable :: Handle -> IO Bool
hIsWritable handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hIsWritable" handle
SemiClosedHandle -> ioe_closedHandle "hIsWritable" handle
htype -> return (isWritable htype)
......@@ -769,7 +786,7 @@ hGetBuffering :: Handle -> IO BufferMode
hGetBuffering handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hGetBuffering" handle
_ ->
{-
......@@ -784,7 +801,7 @@ hIsSeekable :: Handle -> IO Bool
hIsSeekable handle =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hIsSeekable" handle
SemiClosedHandle -> ioe_closedHandle "hIsSeekable" handle
AppendHandle -> return False
......@@ -815,7 +832,7 @@ hSetEcho handle on = do
else
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hSetEcho" handle
_ -> do
rc <- setTerminalEcho (haFO__ handle_) (if on then 1 else 0) -- ConcHask: SAFE, won't block
......@@ -831,7 +848,7 @@ hGetEcho handle = do
else
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hGetEcho" handle
_ -> do
rc <- getTerminalEcho (haFO__ handle_) -- ConcHask: SAFE, won't block
......@@ -844,7 +861,7 @@ hIsTerminalDevice :: Handle -> IO Bool
hIsTerminalDevice handle = do
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "hIsTerminalDevice" handle
_ -> do
rc <- isTerminalDevice (haFO__ handle_) -- ConcHask: SAFE, won't block
......@@ -923,7 +940,7 @@ getHandleFd :: Handle -> IO Int
getHandleFd handle =
withHandle_ handle $ \ handle_ -> do
case (haType__ handle_) of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle "getHandleFd" handle
_ -> do
fd <- getFileFd (haFO__ handle_)
......@@ -946,17 +963,20 @@ ioeGetFileName :: IOError -> Maybe FilePath
ioeGetErrorString :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
ioeGetHandle (IOError h _ _ _) = h
ioeGetErrorString (IOError _ iot _ str) =
ioeGetHandle (IOException (IOError h _ _ _)) = h
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"
ioeGetFileName (IOError _ _ _ str) =
ioeGetFileName (IOException (IOError _ _ _ str)) =
case span (/=':') str of
(_,[]) -> Nothing
(fs,_) -> Just fs
ioeGetFileName _ = error "IO.ioeGetFileName: not an IO error"
\end{code}
'Top-level' IO actions want to catch exceptions (e.g., forkIO and
......@@ -1019,11 +1039,11 @@ wantReadableHandle :: String -> Handle -> (Handle__ -> IO a) -> IO a
wantReadableHandle fun handle act =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle fun handle
SemiClosedHandle -> ioe_closedHandle fun handle
AppendHandle -> ioError not_readable_error
WriteHandle -> ioError not_readable_error
AppendHandle -> ioException not_readable_error
WriteHandle -> ioException not_readable_error
_ -> act handle_
where
not_readable_error =
......@@ -1042,21 +1062,21 @@ wantWriteableHandle_ fun handle act =
checkWriteableHandle fun handle handle_ act
= case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioError (IOException theError)
ClosedHandle -> ioe_closedHandle fun handle
SemiClosedHandle -> ioe_closedHandle fun handle
ReadHandle -> ioError not_writeable_error
_ -> act
where
not_writeable_error =
IOError (Just handle) IllegalOperation fun
("handle is not open for writing")
IOException (IOError (Just handle) IllegalOperation fun
("handle is not open for writing"))
wantRWHandle :: String -> Handle -> (Handle__ -> IO a) -> IO a
wantRWHandle fun handle act =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle fun handle
SemiClosedHandle -> ioe_closedHandle fun handle
_ -> act handle_
......@@ -1065,15 +1085,15 @@ wantSeekableHandle :: String -> Handle -> (Handle__ -> IO a) -> IO a
wantSeekableHandle fun handle act =
withHandle_ handle $ \ handle_ -> do
case haType__ handle_ of
ErrorHandle theError -> ioError theError
ErrorHandle theError -> ioException theError
ClosedHandle -> ioe_closedHandle fun handle
SemiClosedHandle -> ioe_closedHandle fun handle
_ -> act handle_
where
not_seekable_error =
IOError (Just handle)
IllegalOperation fun
("handle is not seekable")
IOException (IOError (Just handle)
IllegalOperation fun
("handle is not seekable"))
\end{code}
......@@ -1082,7 +1102,8 @@ access to a closed file.
\begin{code}
ioe_closedHandle :: String -> Handle -> IO a
ioe_closedHandle fun h = ioError (IOError (Just h) IllegalOperation fun "handle is closed")
ioe_closedHandle fun h = ioError (IOException (IOError (Just h) IllegalOperation fun
"handle is closed"))
\end{code}
Internal helper functions for Concurrent Haskell implementation
......
% ------------------------------------------------------------------------------
% $Id: PrelIO.lhs,v 1.14 2000/07/07 11:03:58 simonmar Exp $