pcall

From Garry's Mod
Jump to: navigation, search
 pcall( )

Contents

Description

Calls a function and catches an error that can be thrown while the execution of the call.

BUG

Using this function with include will break autorefresh.

Issue Tracker: #1976

BUG

This cannot stop errors from hooks called from the engine.

Issue Tracker: #2036

BUG

This does not stop Error and ErrorNoHalt from sending error messages to the server (if called clientside) or calling the GM:OnLuaError hook. The success boolean returned will always return true and thus you will not get the error message returned. error does not exhibit these behaviours.

Issue Tracker: #2498

BUG

This does not stop errors incurred by include.

Issue Tracker: #3112

Arguments

function func

Function to be executed and of which the errors should be caught of

Arguments

vararg arguments

Arguments to call the function with.

Returns

boolean

If the function had no errors occur within it.

Returns

vararg

If an error occurred, this will be a string containing the error message. Otherwise, this will be the return values of the function passed in.

Examples

Example

Catch an error.

local succ, err = pcall(function() aisj() end)
print(succ, err)

Output:

false attempt to call global 'aisj' (a nil value)
Personal tools
Navigation