Skip to main content

error

Function error 

Source
pub fn error(message: any, level: option<number>)
Expand description

Raises an error with message as the error object. This function never returns.

Usually, error adds some information about the error position at the beginning of the message, if the message is a string. The level argument specifies how to get the error position: with level 1 (the default), the error position is where error was called; level 2 points the error to where the function that called error was called; level 0 avoids adding position information.

§Examples

local ok, err = pcall(function()
  error("something broke")
end)
print(ok, err)    --> false   input:2: something broke
error({ code = 42 })         -- any value can be an error object