9951 explained code solutions for 126 technologies


luaHow to throw exception


In order to raise error, use error() function:

function test()
  error()
endctrl + c
function test()

sample function that will always return an error

error()

raises error in Lua


Usage example

function test()
  error()
end

test()
output
lua: (error object is a nil value)
stack traceback:
    [C]: in function 'error'
    /tmp/test.lua:2: in function 'test'
    /tmp/test.lua:5: in main chunk
    [C]: in ?