Type Function
Library (globals)
Return value String
Revision Release 2024.3703
Keywords error, exception, error handling, error message
See also pcall()


Terminates the last protected function called (see: pcall()) and returns the first argument as the error message.

Usually, error() adds some information about the error position at the beginning of the message.


error( message [, level] )
message (required)

String. The message to be returned with the error.

level (optional)

Number. Specifies how to get the error position. With Level 1 (the default), the error position is where the error function was called. Level 2 points the error to where the function that called error was called; and so on. Passing a level 0 avoids the addition of error position information to the message.