Skip to content

Error

Error is raised for system and I/O failures.

It can be subclassed for library-specific operational failures.

Constructor

Error message :code?

Creates a system error.

Parameters:

Name Type Description
message str Error message
code ErrorCode? Underlying platform code
let error = Error "operation failed" code: $sys.linux.Errno.EIO
try
  fs.read "/definitely/missing"
catch Error: err
  echo $Str(err)

str(err) returns the underlying system error message and appends the native symbolic code in parentheses when it is known.

Fields

code

code contains the underlying native system error code when one exists:

try
  fs.read "/definitely/missing"
catch Error: err
  echo $err.code

The value is sys.linux.Errno, sys.freebsd.Errno, sys.macos.Errno, or sys.windows.WinError, according to the system where the error originated. Errors without a native code expose nil.

Inherits