|
| 20 Jun 2015 06:08 PM |
I know I have been asking a lot lately but I'm trying to do and learn something I have never done before
I know how pcall works but I want to catch the error, therefore, I remebered ready something about xpall. I can't find the wiki page, so can someone just give me an example? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Jun 2015 06:10 PM |
| xpcall(function() ogm("Error not a real global") end, function(...) print("[ERR]", ...) end) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 06:10 PM |
w-what
that doesnt....that doesnt e- what? what the hell is xpall?
do u mean ypcall????? |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 06:14 PM |
http://wiki.roblox.com/index.php?title=Xpcall#xpcall_.28f.2C_err.29
Basically what it does is it takes the error and passes it to a function you give it, then will return if it ran successfully and what your error function returned:
function Handler(error_string) return "'"..error_string.."' was the error" end
print(xpcall(function() print(1 .. 2) --[[Error was concatenating numbers]] end, Handler))
@above ypcall and pcall are the same thing -_- |
|
|
| Report Abuse |
|
|
Usering
|
  |
| Joined: 18 Aug 2012 |
| Total Posts: 10281 |
|
|
| 20 Jun 2015 06:18 PM |
"@above ypcall and pcall are the same thing -_-"
ypcall = yield pcall pcall = pcall
'yield' in pcall means that it won't break if there's a wait() function in your pcall statement.
I'm not sure whats different between xpcall and pcall, since they both return the same stuff
local error,message = pcall(function()prnti("hi, lol") end) if error then print(message) else print("ran successfully") end |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 20 Jun 2015 06:20 PM |
| As I recall, the difference is that xpcall allows you to set your own error handling function, rather than just returning the information like pcall does. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Jun 2015 06:22 PM |
| Usering, pcall is able to yield ever since like 2-3 years ago? since Roblox changed it, so ypcall is useless now |
|
|
| Report Abuse |
|
|
jode6543
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 5363 |
|
|
| 20 Jun 2015 06:25 PM |
| They never changed xpcall to allow for yielding, though, so keep that in mind. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 06:25 PM |
"Usering, pcall is able to yield ever since like 2-3 years ago? since Roblox changed it, so ypcall is useless now"
if it can some Wiki articles are outdated |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 06:26 PM |
| You're correct, some Wiki articles are outdated. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2015 08:08 PM |
A yielding xpcall:
function xpcall(func, handler) local status, result = pcall(func) if not status then return status, handler(result) else return status, result end end |
|
|
| Report Abuse |
|
|