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

WinBatch
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

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

Two-Minute Lecture on ErrorMode Function No-Nos

Keywords:   errormode(@off) errormode(@cancel)

Read ALL the stuff about errormode in the manual. Only disable Errormode for one line at a time. Turning Errormode(@off) is a very big no-no almost all the time.
  1. Use of Errormode indiscriminately will turn a 5 minute debugging project into a 6 week project.

  2. ONLY put error mode 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)

  3. The problem is that the most mindless errors that you do not bother to check for will be the ones that set up a condition that causes a catastrophe 20 statements later.

  4. Here's the famous case:

    User writes a script that deletes all the temp files from his temp directory at startup. Sometimes there are no files so errors were suppressed to avoid messages. Script read:

            ErrorMode(@OFF)
            DirChange("C:\TEMP")
            FileDelete("*.*")
    
    and he put the script in his startup directory. Everything ran fine for months.

    Then, being short of disk space on C:, moved the temp directory to D:\TEMP

    Next time boot up occurred, the script was run. The DirChange failed but because error mode was @OFF, the script continued to run.

    Needless to mention, the FileDelete("*.*") performed flawlessly. Too bad it was not pointing to any intended directory.

  5. Use of ErrorMode(@OFF) at the top of your script WILL nail you every time. Basically your Faustian bargains are:

    • Your script will sometimes put an error message up in front of the user for untrapped errors. Your programming abilities will be held up to ridicule.

    • Your script will occasionally trash a computer requiring reformatting the hard drive and re-installing windows, losing all the users files in the process. This will be pointed out to your management. The humor of the situation will not be a migitating factor.

  6. 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.

    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
    

Article ID:   W12710
Filename:   Two Minute Lecture on ErrorMode No-Nos.txt
File Created: 2003:03:19:08:28:48
Last Updated: 2003:03:19:08:28:48