2.7 – Error Handling

Because Lua is an extension language, all Lua actions start from C code in the host program calling a function from the Lua library (see 3.15). Whenever an error occurs during Lua compilation or execution, control returns to C, which can take appropriate measures (such as print an error message).

Lua code can explicitly generate an error by calling the error function (see 5.1). If you need to catch errors in Lua, you can use the pcall function (see 5.1).