VBScript

By Bryan Muehlberger, ITworld |  How-to

This week we discuss error handling within VBScript. While writing
scripts it is sometimes useful to capture the errors in your code as
they occur and control how they are handled. By default, VBScript will
usually exit if you do not handle the errors appropriately, which may
not be the behavior that you expect.

In order for a VBScript to continue when an error has occurred, you need
to know about two different items. First, there are the statements:

On Error Resume Next (This turns on the error handling capabilities)
On Error GoTo 0 (This turns off the error handling capabilities)

Next, there is the Err object. Once error handling has been enabled
using the "On Error Resume Next" statement, you can use the "Err" object
to find out what has occurred. This object captures all of the
pertinent information relating to the most recent error and allows you
to find out more about it. There are many different properties and
methods associated with the Err object, but the most important are:

Err.Description (gives a description of the error)
Err.Number (the error code that was associated with the error)
Err.Raise (initiates an error code)
Err.Clear (clears the values of the Err object

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness