Why is the pcall not catching both the errors in the sample code below?
It seems to catch the error, but then also reports a stack dump?
local success, message = pcall(function()
-- Error 1
wait(UNDEFINED_VARIABLE)
-- Error 2
if not UnDefinedPlayerData[player] then
-- Test
end
end)
if not success then
print("My Pcall error: ", message)
end
Output:
[My Pcall error: ServerScriptService.Script:7: attempt to index global ‘UnDefinedPlayerData’ (a nil value)]
[14:49:45.160 - ServerScriptService.Script:7: attempt to index global ‘UnDefinedPlayerData’ (a nil value)]
14:49:45.160 - Stack Begin
[14:49:45.160 - Script ‘ServerScriptService.Script’, Line 7]
So having a wait() inside a pcall will cause it to report the errors?
Does that mean that the error will not be caught at all, and the code will break due to the exception? Or does the reporting just sneak through, and the error is still caught?
Also its not supposed to catch all errors, it catches whatever error happens to occur if there is one. You cannot make a single thread or protected call error more than once because it errors and exits.