Handling Script Errors
When scripting CRT with VBScript there are a couple of possible ways of dealing with script errors. For simple scripts, one possibility is to assume that the script will work properly, and not deal with runtime errors that may occur. For example, the call to Connect in the following code sample might fail if the host defined for the æserverÆ session is down or invalid for some reason:
In the case of a Connect failure CRT will generate a runtime error that by default will display an error message and terminate the script. For simple scripts that may desired or sufficient behavior.
For more robust error handling a CRT script should use the VBScript statement "On Error Resume Next". Placing this statement at the top of a routine tells VBScript not to terminate the script, but to set the æErrÆ object and continue execution. This makes the script responsible for handling failures. In the event of a runtime error, scripts that handle these errors should check the value of VBScriptÆs æErrÆ object after calls to CRT functions that may fail. A revised example that handles failures with Connect might look like this:
See also: