49
edits
m (Move page script moved page API pcall to WoW:API pcall without leaving a redirect) |
No edit summary |
||
| Line 18: | Line 18: | ||
== Example == | == Example == | ||
<pre> | |||
function myTest(incrementVal) | |||
return incrementVal + 10; | |||
end | |||
local retOK, ret1 = pcall(myTest,"string value"); | |||
local msg = ""; | |||
if retOK then | |||
msg = "Function succeeded, result: " .. ret1 .. "."; | msg = "Function succeeded, result: " .. ret1 .. "."; | ||
else | |||
msg = "Function failed, error text: " .. ret1 .. "."; | msg = "Function failed, error text: " .. ret1 .. "."; | ||
end | |||
DEFAULT_CHAT_FRAME:AddMessage(msg); | |||
</pre> | |||
====Result==== | ==== Result ==== | ||
pcall will catch the error that | 'pcall' will catch the error that occurred within 'myTest', and output the appropriate text to the default chat window. If "string value" is replaced by a number, the code will output number+10 instead. | ||
==Details== | ==Details== | ||
: pcall will ''also'' return other arguments returned from the "function" if all is successful. | : pcall will ''also'' return other arguments returned from the "function" if all is successful. | ||