The WIL Tutorial
|
Luckily, there is a WIL system function to help us here: ErrorMode. The ErrorMode function lets you decide what will happen if an error occurs during WIL processing. Here's the syntax:
ErrorMode(mode)Specifies how to handle errors. Parameters:(i) mode = @CANCEL, @NOTIFY, or @OFF. Returns:(i) previous error setting.
Use this command to control the effects of runtime errors. The default is @CANCEL, meaning the execution of the WIL program will be canceled for 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 they 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.
As you can see, the default mode is @CANCEL, and it's a good idea to leave it like this. However, it is quite reasonable to change the mode for sections of your WIL program where you anticipate errors occurring. This is just what we've done in our modified WIL program:
If FileExist("wil.bak") == @TRUE Endif Run("winword.exe", "wil.doc")
Notice how we've used ErrorMode(@OFF) to prevent errors in the If statement section from aborting the WIL program, and then used ErrorMode(@CANCEL) at the end of the that section to change back to the default error mode. This is a good practice to follow. Note: Pay close attention when suppressing errors with the ErrorMode function. When an error occurs, the processing of the ENTIRE line is canceled. 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.
e.g. ErrorMode(@OFF)
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( ) ; CORRECT USAGE
|