Garry's Mod Wiki

pcall

boolean, vararg pcall( function func, vararg arguments )

Description

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

Using this function with include will break autorefresh.
This cannot stop errors from hooks called from the engine.
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.
This does not stop errors incurred by include.

Arguments

1 function func
Function to be executed and of which the errors should be caught of
2 vararg arguments
Arguments to call the function with.

Returns

1 boolean
If the function had no errors occur within it.
2 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.

Example

Catch an error.

local succ, err = pcall(function() aisj() end) print(succ, err)
Output: false attempt to call global 'aisj' (a nil value)

Page Links


Special Pages


Wikis

?

Render Time: 33ms

Session 0
DB GetPage 3
Generate Html 2
SaveChanges 14
Render Body 0
Render Sidebar 12