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

Foreign.C.Error

C-specific Marshalling support: Handling of C "errno" error codes.

  • 1 type
  • 126 values
  • Packagebase-4.20.2.0
  • Exports127
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceError.hs

Haskell representations of errno values

1 declaration
newtypenewtype Errno
#

Haskell representation for errno values. The implementation is deliberately exposed, to allow users to add their own definitions of Errno values.

Constructors

Instances1Eq
  • Eq ErrnoDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.C.Error

Common errno symbols

Different operating systems and/or C libraries often support different values of errno. This module defines the common values, but due to the open definition of Errno users may add definitions which are not predefined.

Errno functions

valueisValidErrno :: Errno -> Bool
#

Yield True if the given Errno value is valid on the system. This implies that the Eq instance of Errno is also system dependent as it is only defined for valid values of Errno.

valuegetErrno :: IO Errno
#

Get the current value of errno in the current thread.

On GHC, the runtime will ensure that any Haskell thread will only see "its own" errno, by saving and restoring the value when Haskell threads are scheduled across OS threads.

valueerrnoToIOError
  1. :: String

    the location where the error occurred

  2. -> Errno

    the error number

  3. -> Maybe Handle

    optional handle associated with the error

  4. -> Maybe String

    optional filename associated with the error

  5. -> IOError
#

Construct an IOError based on the given Errno value. The optional information can be used to improve the accuracy of error messages.

Guards for IO operations that may fail

valuethrowErrnoIf
  1. :: (a -> Bool)

    predicate to apply to the result value of the IO operation

  2. -> String

    textual description of the location

  3. -> IO a

    the IO operation to be executed

  4. -> IO a
#

Throw an IOError corresponding to the current value of getErrno if the result value of the IO action meets the given predicate.

valuethrowErrnoIfRetryMayBlock
  1. :: (a -> Bool)

    predicate to apply to the result value of the IO operation

  2. -> String

    textual description of the location

  3. -> IO a

    the IO operation to be executed

  4. -> IO b

    action to execute before retrying if an immediate retry would block

  5. -> IO a
#

as throwErrnoIfRetry, but additionally if the operation yields the error code eAGAIN or eWOULDBLOCK, an alternative action is executed before retrying.