This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Goof's profile picture

question - how to detect, if a program crash

Started by Goof, 31 December 2012 - 09:58 AM
Goof #1
Posted 31 December 2012 - 10:58 AM
Hello.

does anyone know how to make a detector, that detects if my program is beginning to crash. (
Like in the firewolf crash system)

thanks in advance :)/>
Kingdaro #2
Posted 31 December 2012 - 11:04 AM
This sounds like a job for pcall.


local function stupidFunction()
  callingANilValue()
end

local ok, err = pcall(stupidFunction)
if not ok then
  print(err)
end

pcall stands for "protected call", and it allows you to call functions and catch errors if any. In this example, "ok" is whether or not the function call was successful, and if ok is false, "err" is the error message.
Goof #3
Posted 31 December 2012 - 11:11 AM
Thanks for that. I didnt know that it could be printed, before the error is there. But the pcall worked fine… thank you !

:D/> :D/>