As simple as this.
Why does this error:
local suc,err = pcall(function() wait(1) print(game.anerror) end)
And this doesn't:
local suc,err = pcall(function() print(game.anerror) end)
And is there a way to make neither of them error so I can handle errors properly?
The current answer is incorrect. In standard Lua, you are unable to yield inside of a pcall. However, there are some differences in how this works on Roblox. On Roblox, pcall
and ypcall
are the same, so both will generate an error that is not suppressed.
The problem stems instead from the implementation.
Roblox uses continuations which are a way of specifying what to do after a thread terminates. If a thread yields, those continuations are passed along each time the thread resumes.
However, continuations do not consider error suppression. So, when a thread such as pcall is resumed, the errors will be displayed in the output after it has yielded once.
For now, you will need to wrap each individual statement inside of a pcall to suppress the errors.
You can't yield in a pcall. Use a ypcall instead of a pcall.