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 )): ErrorFields
| Name | Type | Description |
|---|---|---|
stack | dreamwork.exceptions.Stack | nil | The captured call stack this error carries. |
message | string | nil | The error message to display. Defaults to "unknown error" if omitted. |
Operators
| Operator | Operand | Result |
|---|---|---|
concat | any | string |
Methods
capture | Captures the call stack of the calling function into the error, replacing the previous one. |
display | Prints the error and its captured call stack directly to the console using engine.consoleMessageColored, with colored s… |
from | Converts any error value into an error of this class, see toError. |
isEmpty | Checks whether the error's stack has no captured frames. |
reset | Removes all entries from the stack, leaving it empty. |
#Error:capture
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.
| Name | Type | Description |
|---|---|---|
stack_leveloptional | integer | The level of the first captured frame, 1 (the caller) by default. |
#Error:display
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
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.
| Name | Type | Description |
|---|---|---|
value | any | The error value to convert. |
| Type | Name | Description |
|---|---|---|
Error | error_object |
#Error:isEmpty
function Error:isEmpty(): boolean
Checks whether the error's stack has no captured frames.
| Type | Name | Description |
|---|---|---|
boolean | is_empty | Returns true if no frames have been captured, otherwise false. |
#Error:reset
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