VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

Error Handling Rules Overview

This section describes error handling facilities supported in VBScript. Rules are provided to turn of and off the error handling flag, and to inspect 'Err' object properties.

VBScript offers some limited facilities to help your manage runtime errors. Here is a summary of rules that will help you to properly manage runtime errors in your VBScript code:

1. The "On Error Resume Next" statement can be used to turn on the error handling flag.

2. The "On Error GoTo 0" statement can be used to turn off the error handling flag.

3. User defined procedures have their own error handling flags. This means that each user defined procedure should be have its own "On Error Resume Next" or "On Error GoTo 0" statement to turn on or off its own error handling flag.

4. By default, error handling flags of all user defined procedures and the main code are turned off.

5. By default, the host environment provides a built-in object called "Err" to hold runtime error information.

6. When a runtime error occurs, the host environment will set values to properties of the "Err" object and raise a runtime error.

7. When a runtime error is raised and the current error handling flag is on, the host environment will continue to execute the next statement.

8. With the error handling flag turned on, you can inspect "Err" object properties to determine how to handle the error and continue your code execution.

9. When a runtime error is raised in a procedure and the current error handling flag is off, the host environment will stop executing the procedure, transfer execution control to the calling code, and raise the same runtime error in the calling code.

10. When a runtime error is raised in the main code and the current error handling flag is off, the host environment will stop executing the main code, and take some additional steps.

11. When Internet Explorer (IE) gets a runtime error with the error handling flag turned off, it will display small dialog box, if its script debug option is turned on.

12. When Windows Script Host (WSH) gets a runtime error with the error handling flag turned off, it will print out an error message.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

Error Handling Flag and the "Err" Object

Error Handling Rules Overview

 IE Option Setting - Enable Script Debugging

 "On Error Resume Next" - Turning on Error Handling

 "On Error GoTo 0" - Turning off Error Handling

 "Err.Number" and "Err.Clear()" - Error Code and Clear Method

 Built-in "Err" Object Properties and Methods

 "Err.Raise()" - Raising Your Own Errors

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 Printable Copy - PDF Version

Error Handling Rules Overview - Updated in 2015, by Dr. Herong Yang