error
Raises a Lua error whose level is resolved past hidden frames.
Raises a Lua error from the caller. Behaves like the standard Lua error, except the level argument is resolved against the visible stack: frames marked by setstackhidden are skipped when picking the frame whose position is prefixed to the message.
A string or number message is prefixed with source:line: from the resolved frame when level >= 1. Any other message type (including nil) is raised as-is. level = 0 disables the prefix. A negative level, a level past the live stack, or a level that lands on a C frame leaves the message unprefixed.
error(message: any, level: number?): ()Parameters
| Parameter | Type | Description |
|---|---|---|
message | any | Error value. Strings and numbers get the position prefix; other types are raised unchanged. |
level | number? | Visible-stack level, counted from the caller. Defaults to 1. |
Example
local function assertPositive(n)
if n <= 0 then
-- Report the error at the caller's line, not this helper's.
error("expected a positive number", 2)
end
end