SysError¶
Usage
use SysError;
or
import SysError;
This module helps handle system errors.
This module defines the type syserr
, which can encode an error code or
error message and be returned from routines generating an error. Additional
routines are provided to print a useful error message from a syserr
.
The IO module uses these routines in a way that supports error inspection
and rapid prototyping. Most routines in the IO module have two forms.
In one form, a SystemError
is thrown when an error occurs.
In the second form, a syserr
is returned in an out error argument.
- class SystemError: Error¶
SystemError
is a base class forErrors.Error
s generated fromsyserr
. It provides factory methods to create different subtypes based on thesyserr
that is passed.- var err: syserr¶
- var details: string¶
- proc init(err: syserr, details: string = "")¶
- override proc message()¶
Provides a formatted string output for
SystemError
, generated from the internalerr
and thedetails
string.
- proc type fromSyserr(err: syserr, details: string = "")¶
Return the matching
SystemError
subtype for a givensyserr
, with an optional string containing extra details.- Arguments
err – the syserr to generate from
details – extra information to include with the error
- proc type fromSyserr(err: int, details: string = "")
Return the matching
SystemError
subtype for a given error number, with an optional string containing extra details.- Arguments
err – the number to generate from
details – extra information to include with the error
- class BlockingIOError: SystemError¶
BlockingIOError
is the subclass ofSystemError
corresponding toSysBasic.EAGAIN
,SysBasic.EALREADY
,SysBasic.EWOULDBLOCK
, andSysBasic.EINPROGRESS
.- proc init(details: string = "", err: syserr = EWOULDBLOCK: syserr)¶
- class ChildProcessError: SystemError¶
ChildProcessError
is the subclass ofSystemError
corresponding toSysBasic.ECHILD
.- proc init(details: string = "", err: syserr = ECHILD: syserr)¶
- class ConnectionError: SystemError¶
ConnectionError
is the subclass ofSystemError
that serves as the base class for all system errors regarding connections.- proc init(err: syserr, details: string = "")¶
- class BrokenPipeError: ConnectionError¶
BrokenPipeError
is the subclass ofConnectionError
corresponding toSysBasic.EPIPE
andSysBasic.ESHUTDOWN
.- proc init(details: string = "", err: syserr = EPIPE: syserr)¶
- class ConnectionAbortedError: ConnectionError¶
ConnectionAbortedError
is the subclass ofConnectionError
corresponding toSysBasic.ECONNABORTED
.- proc init(details: string = "", err: syserr = ECONNABORTED: syserr)¶
- class ConnectionRefusedError: ConnectionError¶
ConnectionRefusedError
is the subclass ofConnectionError
corresponding toSysBasic.ECONNREFUSED
.- proc init(details: string = "", err: syserr = ECONNREFUSED: syserr)¶
- class ConnectionResetError: ConnectionError¶
ConnectionResetError
is the subclass ofConnectionError
corresponding toSysBasic.ECONNRESET
.- proc init(details: string = "", err: syserr = ECONNRESET: syserr)¶
- class FileExistsError: SystemError¶
FileExistsError
is the subclass ofSystemError
corresponding toSysBasic.EEXIST
.- proc init(details: string = "", err: syserr = EEXIST: syserr)¶
- class FileNotFoundError: SystemError¶
FileNotFoundError
is the subclass ofSystemError
corresponding toSysBasic.ENOENT
.- proc init(details: string = "", err: syserr = ENOENT: syserr)¶
- class InterruptedError: SystemError¶
InterruptedError
is the subclass ofSystemError
corresponding toSysBasic.EINTR
.- proc init(details: string = "", err: syserr = EINTR: syserr)¶
- class IsADirectoryError: SystemError¶
IsADirectoryError
is the subclass ofSystemError
corresponding toSysBasic.EISDIR
.- proc init(details: string = "", err: syserr = EISDIR: syserr)¶
- class NotADirectoryError: SystemError¶
NotADirectoryError
is the subclass ofSystemError
corresponding toSysBasic.ENOTDIR
.- proc init(details: string = "", err: syserr = ENOTDIR: syserr)¶
- class PermissionError: SystemError¶
PermissionError
is the subclass ofSystemError
corresponding toSysBasic.EACCES
andSysBasic.EPERM
.- proc init(details: string = "", err: syserr = EPERM: syserr)¶
- class ProcessLookupError: SystemError¶
ProcessLookupError
is the subclass ofSystemError
corresponding toSysBasic.ESRCH
.- proc init(details: string = "", err: syserr = ESRCH: syserr)¶
- class TimeoutError: SystemError¶
TimeoutError
is the subclass ofSystemError
corresponding toSysBasic.ETIMEDOUT
.- proc init(details: string = "", err: syserr = ETIMEDOUT: syserr)¶
- class IOError: SystemError¶
IOError
is the subclass ofSystemError
that serves as the base class for all errors regarding inputs and their formatting. They are typically not directly generated by the OS, but they are used and emitted by the IO module.- proc init(err: syserr, details: string = "")¶
- class EOFError: IOError¶
EOFError
is the subclass ofIOError
corresponding toSysBasic.EEOF
.- proc init(details: string = "", err: syserr = EEOF: syserr)¶
- class UnexpectedEOFError: IOError¶
UnexpectedEOFError
is the subclass ofIOError
corresponding toSysBasic.ESHORT
.- proc init(details: string = "", err: syserr = ESHORT: syserr)¶
- class BadFormatError: IOError¶
BadFormatError
is the subclass ofIOError
corresponding toSysBasic.EFORMAT
.- proc init(details: string = "", err: syserr = EFORMAT: syserr)¶
- proc ioerror(error: syserr, msg: string, path: string, offset: int(64)) throws¶
Create and throw a
SystemError
if an error occurred, formatting a useful message based on the provided arguments. Do nothing if the error argument does not indicate an error occurred.- Arguments
error – the error code
msg – extra information to include in the thrown error
path – optionally, a path to include in the thrown error
offset – optionally, an offset to include in the thrown error
- Throws
SystemError – A subtype is thrown when the error argument indicates an error occurred
- proc ioerror(errstr: string, msg: string, path: string, offset: int(64)) throws
Create and throw an
IOError
and include a formatted message based on the provided arguments.- Arguments
errstr – the error string
msg – extra information to print after the error description
path – a path to print out that is related to the error
offset – an offset to print out that is related to the error
- Throws
IOError – always throws an IOError
- proc errorToString(error: syserr): string¶
Convert a syserr code to a human-readable string describing the error.
- Arguments
error – the error code
- Returns
a string describing the error