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
How to handle system errors?
Moderators: Dorian (MJT support), JRL
- Grovkillen
- Automation Wizard
- Posts: 1062
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: How to handle system errors?
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.
Re: How to handle system errors?
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
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
- Grovkillen
- Automation Wizard
- Posts: 1062
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: How to handle system errors?
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.
Re: How to handle system errors?
Me too.Grovkillen wrote:So my take is to always use a watchdog.
Re: How to handle system errors?
Thanks.
I have implemented a watch dog and it works good
![Very Happy :D](./images/smilies/icon_biggrin.gif)
I have implemented a watch dog and it works good
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Re: How to handle system errors?
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.Massimo wrote:However, in general do you know any method to capture system errors within MS?
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.
Re: How to handle system errors?
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
*/