Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Detecting if a script errors?

Is it possible if when a script errors it triggers a Bindable Event

1 answer

✓ Accepted answer

Yes, by wrapping your code in pcall:

function runCode()
	--your code here
end

if pcall(runCode) then
	--No error!
else
	--It errored...
end

5 comments

0

okay thanks :D

2

You mean pcall(runCode)? Also, I think in general ypcall should be preferred

0

Oh that's useful. It's like a Lua try catch. Is there anyway to use the exception as an argument? In Java try{SOME_CODE;}catch(SOME ERROR){SOME_OTHER_CODE;}

0

@DewnOracle: The second return value of pcall is the error message (as a string). You can use xpcall to get a bit more fine-tuned error handling by passing a function to run (in the erroring scope)

0

That typo is the reason I prefer anonymous functions to doing this. Yeah, ypcall is probably better if the function yields.

This discussion is preserved as it was. New answers, comments, and votes are closed.