Specifies how to handle errors.
ErrorMode (mode)
(i) mode @CANCEL or @NOTIFY or @OFF.
(i) previous error setting.
Use this function to control the effects of runtime errors. The default is @CANCEL, meaning the execution of the WIL program will be canceled upon any error.
@CANCEL: All runtime errors will cause execution to be canceled. The user will be notified which error occurred.
@NOTIFY: All runtime errors will be reported to the user, and the user can choose to continue if it isn't fatal.
@OFF: Minor runtime errors will be suppressed. Moderate and fatal errors will be reported to the user. User has the option of continuing if the error is not fatal.
In general, we suggest the normal state of the program should be ErrorMode(@CANCEL), especially if you are writing a WIL program for others to use. You can always suppress errors you expect will occur and then re-enable ErrorMode (@CANCEL).
ONLY put ErrorMode(@OFF) around SINGLE statements where you are handling the errors yourself. If it is obvious that there is no way a statement could fail, it should be run with ErrorMode(@CANCEL)
Note: Pay close attention when suppressing errors with the ErrorMode function. When an error occurs, the processing of the ENTIRE line is canceled. The value returned from the function is 0. Setting the ErrorMode( ) to @OFF or @NOTIFY allows execution to resume at the next line. Various parts of the original line may have not been executed.
Please read examples very carefully before running.
e.g.
ErrorMode(@off) ; The FileCopy will cause a file not found error, ; canceling the execution of the whole line. ; The variable A is set to @FALSE by default A = FileCopy( "xxxxxxxxx", "*.*", @false) ; ; Now there is a NOT symbol in front of the FileCopy. ; Nonetheless, if an error occurs A is still set to @FALSE ; not @TRUE as might be assumed. When an error is suppressed ; with ErrorMode the line is canceled, and any assignment is ; simply set to the default @FALSE value. A = !FileCopy("yyyyyyyyy", "*.*", @false) Message("ErrorMode","ErrorMode executed.")
For this reason, ErrorMode( ) must be used with a great deal of care. The function for which the errors are being suppressed should be isolated from other functions and operators as much as possible.
e.g.
; INCORRECT USAGE of ErrorMode( ) ; In this instance, when the copy has an error, the entire if ; statement is canceled. ; Execution begins (erroneously) at the next line, and states ; that the copy succeeded. Next a fatal error occurs as the ; "else" is found, since it does not have a matching if ErrorMode(@off) If FileCopy(file1,file2,@false) == @true Message("Info", "Copy worked") Else Message("Error", "Copy failed") EndIf
; CORRECT USAGE ; In this case, the FileCopy is isolated from other statements ; and flow control logic. When the statement fails, execution ; can safely begin at the next line. The variable "a" will ; contain the default value of zero that a failed assignment ; returns. ; Results are not confused by the presence of other operators. ErrorMode(@off) a = FileCopy(file1,file2,@false) ErrorMode(@cancel) If a == @true Message("Info", "Copy worked") Else Message("Error", "Copy failed") EndIf
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. Windows system errors see Microsoft's website: Windows System Error Codes