1
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
2
-- apparent bug in GHC, reports a bogus warning for the Prelude import below
3
module System.IO.Error (
5
IOError, -- = IOException
7
userError, -- :: String -> IOError
9
mkIOError, -- :: IOErrorType -> String -> Maybe Handle
10
-- -> Maybe FilePath -> IOError
12
annotateIOError, -- :: IOError -> String -> Maybe Handle
13
-- -> Maybe FilePath -> IOError
15
-- ** Classifying I\/O errors
16
isAlreadyExistsError, -- :: IOError -> Bool
25
-- ** Attributes of I\/O errors
26
ioeGetErrorString, -- :: IOError -> String
27
ioeGetHandle, -- :: IOError -> Maybe Handle
28
ioeGetFileName, -- :: IOError -> Maybe FilePath
30
-- * Types of I\/O error
31
IOErrorType, -- abstract
33
alreadyExistsErrorType, -- :: IOErrorType
34
doesNotExistErrorType,
35
alreadyInUseErrorType,
38
illegalOperationErrorType,
42
-- * Throwing and catching I\/O errors
44
ioError, -- :: IOError -> IO a
46
catch, -- :: IO a -> (IOError -> IO a) -> IO a
47
try -- :: IO a -> IO (Either IOError a)
51
import "base" System.IO.Error hiding (IOError,catch,try)
52
import qualified "base" System.IO.Error as Base
53
import Prelude hiding (IOError,catch)
55
-- | Errors of type 'IOError' are used by the 'IO' monad. This is an
56
-- abstract type; the module "System.IO.Error" provides functions to
57
-- interrogate and construct values of type 'IOError'.
58
type IOError = Base.IOError
60
-- SDM: duplicated docs for catch and try, omitting the part about non-IO
63
-- | The 'catch' function establishes a handler that receives any 'IOError'
64
-- raised in the action protected by 'catch'. An 'IOError' is caught by
65
-- the most recent handler established by 'catch'. These handlers are
66
-- not selective: all 'IOError's are caught. Exception propagation
67
-- must be explicitly provided in a handler by re-raising any unwanted
68
-- exceptions. For example, in
70
-- > f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)
72
-- the function @f@ returns @[]@ when an end-of-file exception
73
-- (cf. 'System.IO.Error.isEOFError') occurs in @g@; otherwise, the
74
-- exception is propagated to the next outer handler.
76
-- When an exception propagates outside the main program, the Haskell
77
-- system prints the associated 'IOError' value and exits the program.
79
catch :: IO a -> (IOError -> IO a) -> IO a
82
-- | The construct 'try' @comp@ exposes IO errors which occur within a
83
-- computation, and which are not fully handled.
85
try :: IO a -> IO (Either IOError a)