ReferenceDebug

error

Raises an error and stops the current call unless it is caught.

Syntax

error(message: any, level: number?) -> never

Parameters

ParameterTypeDescription
messageanyError value to raise.
levelnumber?Caller level used for location information when applicable.

Description

Use pcall or xpcall to handle an expected failure. Error values can be strings or other Luau values; a protected call receives the raised value. A zero level omits the location prefix for a string message.

Example

local ok, message = pcall(function()
    error("Invalid input", 0)
end)
print(ok, message)

These are Game executor contracts. Check build requirements and session lifetimes before using them.