Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Felthry

Timer continues executing after program crash

Question

I've tried everything I can find to figure out how to stop this from happening, but since I can't seem to find anything at all, I'll put it here.

 

I have a program that relies on a timer to execute some control logic periodically. The code currently has a fatal error in it and crashes, but I haven't been able fix it because I'm not able to use the computer afterward without rebooting it, because the timer event that the program starts apparently never stops, so no matter what I'm doing with the computer, every fifteen seconds it spits out a timestamp followed by "Checking inventory.... Press TAB to exit.". Even though the program that started the timer has crashed.

 

Now, I understand that the timer ends up as a global object or whatever it is that doesn't go away until explicitly destroyed by a call to event.cancel(). What I can't figure out is how to catch a crash--any crash--and destroy this timer so that it doesn't keep running this subroutine while I'm trying to debug.

 

My first thought was to wrap the whole program in a try ... catch, but apparently those don't exist in Lua and I can't even begin to understand what's going on with pcall and xpcall; trying to wrap the main function in them doesn't seem to do anything.

 

Any help would be greatly appreciated.

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  • Solution

Did you remember to pass your main function, rather than the results of executing the main function, to pcall.  Your error handling code should probably look something like this (if you're using pcall):

local ok, err = pcall(main) -- notice no ()
if not ok then
  stopTimer()
  print(err)
end
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.