Xpcall: Difference between revisions
From GiderosMobile
No edit summary |
No edit summary |
||
| (10 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
'''Class:''' [[(global)]]<br/> | |||
=== Description === | === Description === | ||
'''pcall''' function ''f'' with a new error handler ''err''. | |||
The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. | <syntaxhighlight lang="lua"> | ||
xpcall(f,err) | |||
</syntaxhighlight> | |||
The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. | |||
=== Parameters === | === Parameters === | ||
'''f''': (function) | '''f''': (function) pcall function<br/> | ||
'''err''': (string) < | '''err''': (string) error message<br/> | ||
=== Example === | |||
<syntaxhighlight lang="lua"> | |||
-- @oleg ;-) | |||
function f () | |||
return "a" + 2 | |||
end -- f | |||
function err(x) | |||
print ("err called", x) | |||
return "oh no!" | |||
end -- err | |||
print(xpcall(f, err)) | |||
-- err called code.lua:512: attempt to perform arithmetic (add) on string and number | |||
-- false oh no! | |||
</syntaxhighlight> | |||
=== See also === | |||
'''https://luau.org/library#global-functions'''<br/> | |||
{{(global)}} | |||
Latest revision as of 10:29, 21 July 2025
Available since: Gideros 2011.6
Class: (global)
Description
pcall function f with a new error handler err.
xpcall(f,err)
The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine.
Parameters
f: (function) pcall function
err: (string) error message
Example
-- @oleg ;-)
function f ()
return "a" + 2
end -- f
function err(x)
print ("err called", x)
return "oh no!"
end -- err
print(xpcall(f, err))
-- err called code.lua:512: attempt to perform arithmetic (add) on string and number
-- false oh no!
See also
https://luau.org/library#global-functions