base-4.7.0.0: Basic libraries

Copyright(c) The University of Glasgow 2001
LicenseBSD-style (see the file libraries/base/LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

System.IO.Error

Contents

Description

Standard IO Errors.

Synopsis

I/O errors

type IOError = IOException Source

The Haskell 2010 type for exceptions in the IO monad. Any I/O operation may raise an IOError instead of returning a result. For a more general type of exception, including also those that arise in pure code, see Control.Exception.Exception.

In Haskell 2010, this is an opaque type.

userErrorStringIOError Source

Construct an IOError 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)

mkIOErrorIOErrorTypeStringMaybe HandleMaybe FilePathIOError Source

Construct an IOError 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.

annotateIOErrorIOErrorStringMaybe HandleMaybe FilePathIOError Source

Adds a location description and maybe a file path and file handle to an IOError. If any of the file handle or file path is not given the corresponding value in the IOError remains unaltered.

Classifying I/O errors

isAlreadyExistsErrorIOErrorBool Source

An error indicating that an IO operation failed because one of its arguments already exists.

isDoesNotExistErrorIOErrorBool Source

An error indicating that an IO operation failed because one of its arguments does not exist.

isAlreadyInUseErrorIOErrorBool Source

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).

isFullErrorIOErrorBool Source

An error indicating that an IO operation failed because the device is full.

isEOFErrorIOErrorBool Source

An error indicating that an IO operation failed because the end of file has been reached.

isIllegalOperationIOErrorBool Source

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.

isPermissionErrorIOErrorBool Source

An error indicating that an IO operation failed because the user does not have sufficient operating system privilege to perform that operation.

isUserErrorIOErrorBool Source

A programmer-defined error value constructed using userError.

Attributes of I/O errors

Types of I/O error

data IOErrorType Source

An abstract type that contains a value for each variant of IOError.

alreadyExistsErrorTypeIOErrorType Source

I/O error where the operation failed because one of its arguments already exists.

doesNotExistErrorTypeIOErrorType Source

I/O error where the operation failed because one of its arguments does not exist.

alreadyInUseErrorTypeIOErrorType Source

I/O error where the operation failed because one of its arguments is a single-use resource, which is already being used.

fullErrorTypeIOErrorType Source

I/O error where the operation failed because the device is full.

eofErrorTypeIOErrorType Source

I/O error where the operation failed because the end of file has been reached.

illegalOperationErrorTypeIOErrorType Source

I/O error where the operation is not possible.

permissionErrorTypeIOErrorType Source

I/O error where the operation failed because the user does not have sufficient operating system privilege to perform that operation.

userErrorTypeIOErrorType Source

I/O error that is programmer-defined.

IOErrorType predicates

isAlreadyExistsErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because one of its arguments already exists.

isDoesNotExistErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because one of its arguments does not exist.

isAlreadyInUseErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because one of its arguments is a single-use resource, which is already being used.

isFullErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because the device is full.

isEOFErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because the end of file has been reached.

isIllegalOperationErrorTypeIOErrorTypeBool Source

I/O error where the operation is not possible.

isPermissionErrorTypeIOErrorTypeBool Source

I/O error where the operation failed because the user does not have sufficient operating system privilege to perform that operation.

isUserErrorTypeIOErrorTypeBool Source

I/O error that is programmer-defined.

Throwing and catching I/O errors

ioErrorIOErrorIO a Source

Raise an IOError in the IO monad.

catchIOErrorIO a → (IOErrorIO a) → IO a Source

The catchIOError function establishes a handler that receives any IOError raised in the action protected by catchIOError. An IOError is caught by the most recent handler established by one of the exception handling functions. These handlers are not selective: all IOErrors are caught. Exception propagation must be explicitly provided in a handler by re-raising any unwanted exceptions. For example, in

f = catchIOError 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.

Non-I/O exceptions are not caught by this variant; to catch all exceptions, use catch from Control.Exception.

Since: 4.4.0.0

tryIOErrorIO a → IO (Either IOError a) Source

The construct tryIOError comp exposes IO errors which occur within a computation, and which are not fully handled.

Non-I/O exceptions are not caught by this variant; to catch all exceptions, use try from Control.Exception.

Since: 4.4.0.0

modifyIOError ∷ (IOErrorIOError) → IO a → IO a Source

Catch any IOError that occurs in the computation and throw a modified version.