proper error handling? #1688
Replies: 6 comments
-
Posted at 2024-04-19 by @gfwilliams Probably the best idea is to use the hardware watchdog - that's what they have them built in for: https://www.espruino.com/Reference#l_E_enableWatchdog So:
If the function doesn't complete to the point that But you might also want to look at https://www.espruino.com/Debugger#debugging-when-not-connected - at least then when it stops working you can maybe connect and get some idea what happened? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-19 by DanDyse Thank you Gorden, this sounds perfect. Actually I could just set
And it will restart the whole thing whenever anything breaks / hangs longer than 10 seconds, right? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-22 by @gfwilliams yes, you can do that, but that's only checking that the idle loop is working. If something happened (low memory, And no, it doesn't add any noticeable power usage :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-22 by DanDyse Thank you Gordon. I have the following code:
This is supposed to run some code once per minute. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-23 by @gfwilliams That code should work
Yes, at least twice - I'd generally go for ~5 times the interval, just in case. One thing to note is that once you added the watchdog you can't change it or its interval until the device physically reboots ( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-23 by DanDyse Thank you again, I think I finally understand it – important note indeed! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2024-04-19 by DanDyse
I have a puck running a simple script that is set to advertise every 2000 ms. There is a timeout set that checks battery every 10 minutes, attaches the value to the name of the device so I can see the status of puck's battery by using a BLE scanner on my phone.
I am not sure why but sometimes (after days) the advertising string doesn't change anymore (or keeps being empty), puck is still advertising, but the script is obviously not working anymore.
I believe this is because of some script error that breaks the 10 minutes routine.
So I would like to put the code in some "try-catch" loop that restarts the whole thing in case something odd happens. How to?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions