dreamworkAPI
Ctrl K
GitHub
classDocs / Error

Error

classsharedmenusource
Object → Error

The base error object used throughout dreamwork.

An Error wraps a dreamwork.exceptions.Stack of call frames captured at (or before) the point the error was raised, and provides helpers to turn that stack into a human-readable string (toString/__tostring) or print it directly to the console with colors (display).

Constructor

Error(message: ( string | nil )): Error

Fields

NameTypeDescription
stackdreamwork.exceptions.Stack | nilThe captured call stack this error carries.
messagestring | nilThe error message to display. Defaults to "unknown error" if omitted.

Operators

OperatorOperandResult
concat any string

Methods

captureCaptures the call stack of the calling function into the error, replacing the previous one.
displayPrints the error and its captured call stack directly to the console using engine.consoleMessageColored, with colored s…
fromConverts any error value into an error of this class, see toError.
isEmptyChecks whether the error's stack has no captured frames.
resetRemoves all entries from the stack, leaving it empty.

#Error:capture

sharedmenusource
function Error:capture(stack_level?: integer)

Captures the call stack of the calling function into the error, replacing the previous one.

Hidden frames are left out, the same way error captures them.

Parameters
NameTypeDescription
stack_leveloptionalintegerThe level of the first captured frame, 1 (the caller) by default.

#Error:display

sharedmenusource
function Error:display()

Prints the error and its captured call stack directly to the console using engine.consoleMessageColored, with colored segments for the realm, error type, message, source locations and function references.

This is a display-only counterpart to toString: it writes straight to the console instead of building and returning a string.

#Error:from

sharedmenunodiscardsource
function Error:from(value: any): Error

Converts any error value into an error of this class, see toError.

Values that already are an Error are returned as is, keeping their own class.

Parameters
NameTypeDescription
valueanyThe error value to convert.
Returns
TypeNameDescription
Errorerror_object

#Error:isEmpty

sharedmenunodiscardsource
function Error:isEmpty(): boolean

Checks whether the error's stack has no captured frames.

Returns
TypeNameDescription
booleanis_emptyReturns true if no frames have been captured, otherwise false.

#Error:reset

sharedmenusource
function Error:reset()

Removes all entries from the stack, leaving it empty.

Subclasses

AsyncError, AsyncFileSystemError, DecodeError, EncodeError, EndOfFileError, FluentError, HTTPError, NotImplementedError, RuntimeError, SteamError, TypeError, ValueError, WASMError, lua.SyntaxError

Generated from the dreamwork meta branch.