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

checking for errors

Started by ZagKalidor, 06 April 2017 - 12:02 PM
ZagKalidor #1
Posted 06 April 2017 - 02:02 PM
Hey guys,

i know there is a possibility to check for errors, throwed by the terminal inside some program but i could not find propper solution. Searching with the keyword "error" gives a lot of documents, that can't be read completely. So i try to ask it here. Please appologise if it is a FAQ.

How do i check for errors and continue in a specific way, like

if there is error a then do this…
if there is error b then do that…

Thanks and greetings to all
Zag
Bomb Bloke #2
Posted 06 April 2017 - 04:15 PM
You want pcall.

local ok, result = pcall(someFunc)

if ok then
  -- No error, "result" has the return value of someFunc().

else
  -- Error, "result" is a string with the message.

  if result == "some error" then
    ...

  elseif result == "some other error" then
    ...

  end
end
ZagKalidor #3
Posted 06 April 2017 - 07:01 PM
Thanks Bomb, have to see how to implement this, thx a lot…