Two-Minute Lecture on ErrorMode Function No-NosKeywords: 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.
- Use of Errormode indiscriminately will turn a 5 minute debugging project into a 6 week project.
- 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)
- 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.
- 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.
- 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.
Article ID: W12710Filename: Two Minute Lecture on ErrorMode No-Nos.txt