Xpcall: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
Line 14: Line 14:
'''f''': (function) pcall function<br/>
'''f''': (function) pcall function<br/>
'''err''': (string) error message<br/>
'''err''': (string) error message<br/>
=== Example ===
<syntaxhighlight lang="lua">
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>


{{(global)}}
{{(global)}}

Revision as of 10:05, 5 October 2023

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

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!