Securing OnTimer background scripts so that they continue to run after errors


I have a problem with the background script functionality.
My script works great for weeks and then stops working.

My guess is that a background script stops running after a hard error.

The background script has a “procedure OnTimer;” and
makes an internal web request. (I convert the current playlist to
json and send it into a monitoring system every 15 seconds)

To make a POST request, I’m using a variable

client: IRESTClient; 

and am sending like this (to a python flask server that pipes the playlist into our MQTT server)

 client := CreateRESTClientWithCredentials(MQTT_HOST, '', '');
 client.PostJSON('/mqtt' + MQTT_CHANNEL, build_response);

In other languages I have try/catch code to catch network problems or other hard errors.

Is there something similar so that I can make the OnTimer run every time even
if there’s an error on a previous run?

If not, what’s the best way to find out where the OnTimer job failed?

Looks like there a try/catch

So I’ll try this to see if it helps