Skip to main content

xpcall

Function xpcall 

Source
pub fn xpcall(
    f: function,
    msgh: function,
    args: Repeatable<any>,
) -> (boolean, Repeatable<any>)
Expand description

Like pcall, but sets msgh as a message handler: in case of error, msgh is called with the error object before the stack unwinds, and its return value becomes the error object returned by xpcall.

§Examples

local ok, err = xpcall(function()
  error("boom")
end, function(e)
  return "handled: " .. e
end)
print(ok, err)    --> false   handled: input:2: boom