How to handle system errors?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Massimo
Newbie
Posts: 15
Joined: Sat Dec 28, 2019 5:16 pm

How to handle system errors?

Post by Massimo » Sat Dec 26, 2020 2:17 am

Hi,
I'm writing a program that writes log files to a File Server.
My application is a long running time utility (can last many days).
During execution a disconnection to File server can appear.

In this case the following error appears: Macro Scheduler: I/O Error 53 that stops program execution.

I have used an error handler but the error is not captured.
Do you have any solution or recommendations to prevent the program to stop without control?

Here a short example showing the issue,
The error appears on line:6

1:Let>LOCALVARS=1
2:Let>IGNORERRORS=1
3:Let>ONERROR=ErrHandler
4:Let>LoopLog=Q:\LoopTrack.log
5:Let>LogStri=<----- Program Started ----->
6:DateStamp>LoopLog,LogStri

SRT>ErrHandler
DateStamp>ERROR_LOG_FILE,TTP: %LAST_ERROR_LINE% , %LAST_ERROR%
END>ErrHandler


Thank you
Massimo

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to handle system errors?

Post by Grovkillen » Tue Dec 29, 2020 5:38 am

I have created a watchdog script that monitors the running scripts. The running scripts will write to a ini file each loop iteration. If the ini file isn't updated within the expected time frame the watchdog will terminate that particular script and restart it.
Let>ME=%Script%

Running: 15.0.27
version history

Massi
Newbie
Posts: 6
Joined: Fri Jan 10, 2020 9:05 pm

Re: How to handle system errors?

Post by Massi » Tue Dec 29, 2020 8:45 am

Hi.
Thanks for your answer.
In fact I work with a compiled script (this should not make any difference for your concept).
I understand your solution and I think is a good workaround.

However, in general do you know any method to capture system errors within MS?
MS knows that something went wrong because a message box is displayed with the error.

Massimo

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to handle system errors?

Post by Grovkillen » Sat Jan 02, 2021 1:37 pm

As far as I know only command errors are possible to catch using the "on error" event. Major errors which is crashing the script engine itself aren't possible since it's happening on a higher level. So my take is to always use a watchdog.
Last edited by Grovkillen on Mon Jan 04, 2021 5:51 am, edited 2 times in total.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to handle system errors?

Post by JRL » Sat Jan 02, 2021 8:22 pm

Grovkillen wrote:So my take is to always use a watchdog.
Me too.

User avatar
Massimo
Newbie
Posts: 15
Joined: Sat Dec 28, 2019 5:16 pm

Re: How to handle system errors?

Post by Massimo » Fri Jan 08, 2021 8:10 am

Thanks.
I have implemented a watch dog and it works good
:D

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to handle system errors?

Post by JRL » Fri Jan 08, 2021 1:32 pm

Massimo wrote:However, in general do you know any method to capture system errors within MS?
There are two variables created after the error is closed (assuming the script continues). Last_Error and Last_Error_Line. The first provides the text of the error that was displayed and the second provides the line number where the error occurred.

Haven't really thought about it but it seems like a custom event handler could be written to capture and save the values of those two variables. Then clear their values to reset the event handler. You'd still need the watchdog to close the error message and allow the script to continue.

Or, one might be able to capture an image or maybe even the text in the displayed error message using the watchdog.

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to handle system errors?

Post by JRL » Fri Jan 08, 2021 6:02 pm

Here's a sample script that implements both of the methods I mentioned might be possible. Oddly the Last_Error_Line variable does not record the correct line number. Instead it records the last line of the OnEvent sampling subroutine

Code: Select all

Let>Last_Error=
Let>Last_Error_Line=
Let>vVarMonTest=new
DeleteFile>%temp_dir%ErrorTrap.txt



//The following creates a watchdog script
Let>Per=%
DeleteFile>%temp_dir%watchdog.scp
LabelToVar>Script,vData
WriteLn>%temp_dir%watchdog.scp,wres,vData
ExecuteFile>%temp_dir%watchdog.scp
Wait>1


OnEvent>Custom,srtErrorVarMon,vVarMonTest,srtErrorToDo





//incomplete function to cause an error//
Let>
/////////////////////////////////////////

ExecuteFile>%temp_dir%ErrorTrap.txt

SRT>srtErrorVarMon
  If>Last_Error<>
    Let>Last_Error_Line1=Last_Error_Line
    Let>vVarMonTest=True
  EndIf
END>srtErrorVarMon


SRT>srtErrorToDo
  WriteLn>%temp_dir%ErrorTrap.txt,wres,%crlf%%crlf%Data Captured via Last_Error variables.
  WriteLn>%temp_dir%ErrorTrap.txt,wres,Unfortunately the Last_Error_Line value is the line containing END>srtErrorVarMon.
  WriteLn>%temp_dir%ErrorTrap.txt,wres,=======================================
  WriteLn>%temp_dir%ErrorTrap.txt,wres,Error in: %Script_Name% - Line %Last_Error_Line% - %Last_Error%
  Let>vVarMonTest=False
  Let>Last_Error=
  Let>Last_Error_Line=
END>srtErrorToDo


/*
Script:
Let>BlockMarker={"======================================="}
WaitWindowOpen>Information
SetFocus>Information
Press Ctrl
Send>c
Release Ctrl
Wait>1
GetClipBoard>vClip
WriteLn>%temp_dir%ErrorTrap.txt,wres,Data captured via clipboard from the "Information" window.
WriteLn>%temp_dir%ErrorTrap.txt,wres,BlockMarker
WriteLn>%temp_dir%ErrorTrap.txt,wres,vClip
WriteLn>%temp_dir%ErrorTrap.txt,wres,BlockMarker
Press Enter
*/

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts