Difference between revisions of "Xpcall"

From GiderosMobile
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[(global)]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/(global)|(global)]]<br/>
 
  
=== <translate>Description</translate> ===
+
=== Description ===
<translate>[[Special:MyLanguage/pcall|pcall]] function f with new error handler err. The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine.</translate>
+
'''pcall''' function ''f'' with a new error handler ''err''.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
xpcall(f,err)
 
xpcall(f,err)
</source>
+
</syntaxhighlight>
  
=== <translate>Parameters</translate> ===
+
The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine.
'''f''': (function) <translate>pcall function</translate> <br/>
+
 
'''err''': (string) <translate>error message</translate> <br/>
+
=== Parameters ===
 +
'''f''': (function) pcall function<br/>
 +
'''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>
  
 
{{(global)}}
 
{{(global)}}

Latest revision as of 12:06, 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

-- @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!