How to execute commands when an error occurs
Top  Previous  Next


1) Use the script from the previous undo tutorial

2) Disable the error dialog

Add this line to [Settings]:  

BatchSettings.ErrorDialogDisable=Yes

3) Create the [OnError] section

a) Click file / new section / onerror to create an empty [OnError] section.  
 
b) Fill the section with this code:  

EventLog.Write Error, 770, SetupBatcher Error - %LastErrorCommand% - %LastErrorMsg%
SaveScript
 C:\Err_%date%%time%.cnu


4) Run the script twice

Run it twice to make sure that an error occurs - when the directories exists.  
 
Notice that the error dialog is not displayed anymore.  

5) Verify the result

a) Open the event viewer and check the application log:  
 
 
 
b) Open explorer and go to c:\  
 
 
 
A copy of the script has been saved as c:\Err_2002-08-25.cnu with all markers intact. This setup is very useful when a script is called automatically from the schedule service - when an error occurs it is possible to open the script that failed and retry it from where it stopped in GUI.  
 
Learn more in the topic error handling in the SetupBatcher manual.