IoError

public struct IoError { /* private fields */ }

Structured I/O error: a classified kind plus the originating POSIX errno.

Returned in the Err arm of every Result produced by Read, Write, File, stdio, and the os.fs helpers. Pattern-match on kind for programmatic dispatch; call description() for a short human-readable phrase. The convenience constructors at the bottom (notFound(), permissionDenied(), etc.) build common kinds without spelling the enum.

Examples

match File.open("missing.txt") { .Ok(f) => use(f), .Err(e) => match e.kind { .NotFound => createDefault(), .PermissionDenied => requestAccess(), _ => log(e.description()) } }

Properties

public var kind: IoErrorKind

Initializers

public init(code: Int32)

Builds an error from a raw POSIX errno; classifies the kind.

public init(kind: IoErrorKind)

Builds an error for a categorized kind.

Methods

public func description() -> String

Returns a short human-readable phrase for the error kind. Unknown codes yield "unknown error"; for full coverage use errno() with a platform strerror.

public func errno() -> Int32

The raw POSIX error code. Use for programmatic dispatch when pattern-matching on kind is too coarse — e.g. distinguishing between .Other codes.

public static func last() -> IoError

Snapshots the current value of the platform's errno thread-local. Call immediately after a failed libc call — any other libc activity in between can clobber the value.

Defined in lang/std/io/error.ks