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

How to keep things clean and print the error if a program crashes?

Started by Jummit, 09 December 2018 - 08:21 AM
Jummit #1
Posted 09 December 2018 - 09:21 AM
Normally if I wanted to get the error of a program if it crashes I would just use pcall, clear everything and print the error. But since I often make use of the window api things get messy sometimes.

My question is: How can I ensure that if the program crashes I
  1. Have a completely black screen
  2. Print the error in orange on the first line
  3. Have the cursor (input prompt) on the second line
Edited on 09 December 2018 - 08:23 AM
Lupus590 #2
Posted 09 December 2018 - 10:28 AM
Have the crash handler code make a local copy of the term for it's use before pcalling, so that if the program uses any term redirects it still accesses the term provided by the shell.

On a crash, redirect the screen to your term, clear it and print as normal.
Edited on 09 December 2018 - 09:29 AM
Jummit #3
Posted 09 December 2018 - 01:41 PM
Ok, this is what I did to achieve it:
  1. store the current term
  2. make a window and redirect to it
  3. run pcall
  4. hide window
  5. redirect to term stored in 1.
  6. print error