WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Errormode: Suppressing Errors
Important Information

Keywords:        ErrorMode error mode suppress info information off on

Note before even considering using ErrorMode without a note from your mother read ALL about it in the helpfile/manual - including all the examples. And never (never never never ever) use it to supress errors on more than one line of code at a time. There are horror stories galore when people have done so.

Suppressing errors with the ErrorMode function must be done with great care. When an error occurs, the processing of the entire line is cancelled. Setting the ErrorMode() to @OFF or @NOTIFY allows execution to resume when errors occur. When you turn off error reporting, various parts of the original line may not have been executed.

Here's an example:

ErrorMode(@off)

; This line will cause a "file not found" error when error mode is on. 
; A is set to @FALSE by default

A = FileCopy("XXXXXXXXXXXX","XXXXXXXXXXX",@FALSE)

; Now there is a NOT (!) symbol in front of the FileCopy.  Nonetheless, if a error occurs
; A is still set to @FALSE - not @TRUE as might be assumed.

A =  !FileCopy("XXXXXXXXXXXX","XXX#XXXXXXXX",@FALSE)

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., BAD FORM:

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. Then a fatal error occurs when the "else" is found, since it does not have a matching if statement:

ErrorMode(@OFF)

if FileCopy(file1,file2,@FALSE)
        Message("Info", "Copy worked")
else
        Message("Error","Copy failed")
endif
CORRECT FORM:

In this case, the FileCopy is isolated from other statements and flow control logic. If 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. ErrorMode(@FF) a = FileCopy(file1,file2,@FALSE) ErrorMode(@CANCEL) if a Message("Info", "Copy worked") else Message("Error","Copy failed") endif


Article ID:   W13056
Filename:   ERRORMODE Suppressing Errors Important Info.txt
File Created: 1999:04:15:16:51:28
Last Updated: 1999:04:15:16:51:28