Error Handling

 

There are three types of errors that can occur while processing a WIL program: Minor, Moderate, and Fatal.

§         Minor errors are numbered from 1000 to 1999.

§         Moderate errors are numbered from 2000 to 2999.

§         Fatal errors are numbered from 3000 to 3999.

 

What happens when an error occurs depends on the current error mode, which is set with either the ErrorMode or IntControl 73 functions.

 

Using ErrorMode:

There are three possible modes you can specify:

§         @CANCEL
User is notified when any error occurs, and then the WIL program is canceled. This is the default.

§         @NOTIFY
User is notified when any error occurs, and has option to continue unless the error is fatal.

§         @OFF
User is only notified if the error is moderate or fatal. User has option to continue unless the error is fatal.

The function LastError returns the code of the most-recent error encountered during the currently-executing WIL program.

Error handling is reset to @CANCEL at the start of each WIL program.

Note: You must read the section on the ErrorMode function completely before attempting to use the function to suppress run-time errors. For an example of using ErrorMode, see the function LastError.

 

Using IntControl 73:

Regardless of the type of the error, IntControl 73 lets you specify what should happen when the next error occurs in the script.

 

Getting Extended Error Information:

Most WIL errors are accompanied by 'extended error information'. Extended error information is written to the wwwbatch.ini file:

On XP: "C:\Documents and Settings\{username}\Application Data\WinBatch\Settings\wwwbatch.ini"

On Vista and newer: "C:\Users\{username}\AppData\Roaming\WinBatch\Settings\wwwbatch.ini"

 

There is a section that contains additional diagnostic information that may give some clue as to what it is that failed.  

IntControl 73 returns this same information in the 'wberroradditionalinfo' variable.

Extended error information is most commonly in the form of a Windows system error. For a list of Windows system errors see Microsoft's website: Windows System Error Codes

 

Example:

;GOTO Sample

IntControl(73,1,0,0,0) badline=Message(aaaa,bbb) Exit
:WBERRORHANDLER lasterr = wberrorarray[0] handlerline = wberrorarray[1] textstring = wberrorarray[5] linenumber = wberrorarray[8] errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'") Message("Error Information",errstr) Exit

;GOSUB sample
IntControl(73,2,0,0,0)
badline=Message(aaaa,bbb)
Exit
:WBERRORHANDLER lasterr = wberrorarray[0] handlerline = wberrorarray[1] textstring = wberrorarray[5] linenumber = wberrorarray[8] errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'") Message("Error Information",errstr) IntControl(73,2,0,0,0) ; Re-arm error handler Return
 

;UDF sample
#DefineSubRoutine OnNextError(Err_Array)
   lasterr = wberrorarray[0]
   handlerline = wberrorarray[1]
   textstring = wberrorarray[5]
   linenumber = wberrorarray[8]
   errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'")
   Message("Error Information",errstr)
   Return(1);Re-arm error handler
#EndSubRoutine

IntControl(73,3,0,"OnNextError",0) badline=Message(aaaa,bbb) Exit
 

 

 

 

§         Error Messages

§         LastError

§         WIL Language Elements

§         Reference

§         Step by step guide to learning WIL

§         Notes