Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- type IOError = IOError
- userError :: String -> IOError
- mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError
- annotateIOError :: IOError -> String -> Maybe Handle -> Maybe FilePath -> IOError
- isAlreadyExistsError :: IOError -> Bool
- isDoesNotExistError :: IOError -> Bool
- isAlreadyInUseError :: IOError -> Bool
- isFullError :: IOError -> Bool
- isEOFError :: IOError -> Bool
- isIllegalOperation :: IOError -> Bool
- isPermissionError :: IOError -> Bool
- isUserError :: IOError -> Bool
- ioeGetErrorString :: IOError -> String
- ioeGetHandle :: IOError -> Maybe Handle
- ioeGetFileName :: IOError -> Maybe FilePath
- data IOErrorType
- alreadyExistsErrorType :: IOErrorType
- doesNotExistErrorType :: IOErrorType
- alreadyInUseErrorType :: IOErrorType
- fullErrorType :: IOErrorType
- eofErrorType :: IOErrorType
- illegalOperationErrorType :: IOErrorType
- permissionErrorType :: IOErrorType
- userErrorType :: IOErrorType
- ioError :: IOError -> IO a
- catch :: IO a -> (IOError -> IO a) -> IO a
- try :: IO a -> IO (Either IOError a)
I/O errors
type IOError = IOError Source #
Errors of type IOError
are used by the IO
monad. This is an
abstract type; the module System.IO.Error provides functions to
interrogate and construct values of type IOError
.
userError :: String -> IOError #
Construct an IOException
value with a string describing the error.
The fail
method of the IO
instance of the Monad
class raises a
userError
, thus:
instance Monad IO where ... fail s = ioError (userError s)
mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError #
Construct an IOException
of the given type where the second argument
describes the error location and the third and fourth argument
contain the file handle and file path of the file involved in the
error if applicable.
annotateIOError :: IOError -> String -> Maybe Handle -> Maybe FilePath -> IOError #
Adds a location description and maybe a file path and file handle
to an IOException
. If any of the file handle or file path is not given
the corresponding value in the IOException
remains unaltered.
Classifying I/O errors
isAlreadyExistsError :: IOError -> Bool #
An error indicating that an IO
operation failed because
one of its arguments already exists.
isDoesNotExistError :: IOError -> Bool #
An error indicating that an IO
operation failed because
one of its arguments does not exist.
isAlreadyInUseError :: IOError -> Bool #
An error indicating that an IO
operation failed because
one of its arguments is a single-use resource, which is already
being used (for example, opening the same file twice for writing
might give this error).
isFullError :: IOError -> Bool #
An error indicating that an IO
operation failed because
the device is full.
isEOFError :: IOError -> Bool #
An error indicating that an IO
operation failed because
the end of file has been reached.
isIllegalOperation :: IOError -> Bool #
An error indicating that an IO
operation failed because
the operation was not possible.
Any computation which returns an IO
result may fail with
isIllegalOperation
. In some cases, an implementation will not be
able to distinguish between the possible error causes. In this case
it should fail with isIllegalOperation
.
isPermissionError :: IOError -> Bool #
An error indicating that an IO
operation failed because
the user does not have sufficient operating system privilege
to perform that operation.
isUserError :: IOError -> Bool #
A programmer-defined error value constructed using userError
.
Attributes of I/O errors
ioeGetErrorString :: IOError -> String #
ioeGetHandle :: IOError -> Maybe Handle #
ioeGetFileName :: IOError -> Maybe FilePath #
Types of I/O error
data IOErrorType #
An abstract type that contains a value for each variant of IOException
.
Instances
Eq IOErrorType | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception (==) :: IOErrorType -> IOErrorType -> Bool # (/=) :: IOErrorType -> IOErrorType -> Bool # | |
Show IOErrorType | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception showsPrec :: Int -> IOErrorType -> ShowS # show :: IOErrorType -> String # showList :: [IOErrorType] -> ShowS # |
alreadyExistsErrorType :: IOErrorType #
I/O error where the operation failed because one of its arguments already exists.
doesNotExistErrorType :: IOErrorType #
I/O error where the operation failed because one of its arguments does not exist.
alreadyInUseErrorType :: IOErrorType #
I/O error where the operation failed because one of its arguments is a single-use resource, which is already being used.
fullErrorType :: IOErrorType #
I/O error where the operation failed because the device is full.
I/O error where the operation failed because the end of file has been reached.
illegalOperationErrorType :: IOErrorType #
I/O error where the operation is not possible.
permissionErrorType :: IOErrorType #
I/O error where the operation failed because the user does not have sufficient operating system privilege to perform that operation.
userErrorType :: IOErrorType #
I/O error that is programmer-defined.
Throwing and catching I/O errors
catch :: IO a -> (IOError -> IO a) -> IO a Source #
The catch
function establishes a handler that receives any IOError
raised in the action protected by catch
. An IOError
is caught by
the most recent handler established by catch
. These handlers are
not selective: all IOError
s are caught. Exception propagation
must be explicitly provided in a handler by re-raising any unwanted
exceptions. For example, in
f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)
the function f
returns []
when an end-of-file exception
(cf. isEOFError
) occurs in g
; otherwise, the
exception is propagated to the next outer handler.
When an exception propagates outside the main program, the Haskell
system prints the associated IOError
value and exits the program.