Skip to content

API Error

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 3 revisions

Error

Throwable script error value with a captured stack.

Script API Reference

Overview

Error creates values that can be thrown. The runtime keeps the message and the script call stack, which makes it the right way to report a condition the caller cannot continue past.

Tip

Throw only for genuinely unrecoverable conditions. An expected "not found" outcome is usually better expressed as null or an agreed sentinel value.

Constructors

new Error(message)

Parameters

Name Type Required Description
message string Yes Text describing the failure.

Returns

Error — a throwable error value carrying the message and the captured script stack.

Example

func requirePositive(value) {
    if (value <= 0) throw new Error("value must be positive");
    return value;
}

return requirePositive(3); // 3

Clone this wiki locally