HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebase-4.20.2.0Haskell2010

System.IO.Error

Standard IO Errors.

  • 2 types
  • 44 values
  • Packagebase-4.20.2.0
  • Exports46
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceError.hs

I/O errors

4 declarations
typetype IOError = IOException
#

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

In Haskell 2010, this is an opaque type.

valueuserError :: String -> IOError
#

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)

Classifying I/O errors

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

valueisEOFError :: IOError -> Bool
#

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

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.

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

Attributes of I/O errors

Types of I/O error

10 declarations
datadata IOErrorType
#

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

Instances2Eq, Show
  • Eq IOErrorTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception
  • Show IOErrorTypeDefined in ghc-internal-9.1003.0 · GHC.Internal.IO.Exception

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

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

I/O error where the operation failed because the resource vanished. This happens when, for example, attempting to write to a closed socket or attempting to write to a named pipe that was deleted.

IOErrorType predicates

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

Throwing and catching I/O errors

4 declarations
valuecatchIOError :: IO a -> (IOError -> IO a) -> IO a
#

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.