pcall(f, arg1, ···)
Calls function f
with the given arguments in protected mode. This means that any error inside f
is not propagated; instead, pcall
catches the error and returns a status code. Its first result is the status code (a Boolean), which is true if the call succeeds without errors. In such case, pcall
also returns all results from the call, after this first result. In case of any error, pcall
returns FALSE plus the error message.
Example
ok, result = pcall( myfunction, arg1, arg2, arg3 )
if not ok then error( "myfunction() failed!", 0 ) end