VBS tutorial: object err



Contains information about runtime errors. Accept the raise and clear methods used to generate and clear runtime errors.


The err object is an inherent object with global scope: you don’t have to create an example of it in your code. Err’s properties are set by an error generator: Visual Basic, automatic object, or VBScript program.

The default attribute of the err object is number. Err.number contains an integer and can be used by the automation object to return scode.

When a run-time error occurs, the properties of err are populated with unique information identifying the error and information that can be used to process it. To generate runtime errors in your code, use the raise method.

The err object property was reset to zero or zero length string (”). The clear method can be used to explicitly reset err.

The following example illustrates the use of err objects:

On Error Resume Next
Err. Raise 6 'generated an overflow error.
MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err. Clear 'clear error.

The err object is an internal object with a global scope that contains all the information about the error.
On error resume next ignores all errors generated at runtime
On error goto 0 cancel ignore error action
The main methods are: clear and raise
The main attributes are: description, HelpContext, helpfile, number and source

For detailed description of its properties and methods, see the following example description:

Method of err object


Description: clear all the current properties of err object, that is, clear error
Syntax: err.clear


On error resume next ‘ignore all errors generated at runtime
MsgBox 5/0
Msgbox err. Number ‘output wrong value
Err. Clear ‘clear all error messages
Msgbox err. Number ‘output 0


Description: defines a runtime error
Syntax: err. Raise (number, source, description, helpfile, helpcontent)
Parameter: Number: used to mark the error number
The source tag generates the wrong object or application name
Description: description information about the error
Helpfile: a valid path to the help file
Helpcontent: the topic of the help file


On Error Resume Next
Err. Raise 22, “vbs script”, “overflow”, “C: \ test. TXT” ‘defines a runtime error
Msgbox “error:” & vbcrlf_
& “Number:” & Err.Number & vbCrLf _
& “Source:” & Err.Source & vbCrLf _
& “Description:” & Err.Description & vbCrLf _
& “Helpfile:” & Err.HelpFile
Err. Clear ‘clear error

Properties of err objects


Description: returns or sets the description of the error
Syntax: description (conid)


Description = err. Description ‘returns the description information of error
Err.description = “type mismatch” ‘set the description of error


Description: returns or sets the topic of the specified help information
Syntax: HelpContext (string)


HelpContext = err. HelpContext ‘returns the help topic of error
Err. HelpContext = “type mismatch” ‘set the help topic for error


Description: returns or sets the address of the help file
Syntax: helpfile (filepath)


Helpfile = err. Helpfile ‘returns the address of the helpfile
Err. Helpfile = “C: \ test. TXT” ‘set the address of helpfile


Description: returns or sets a numeric value indicating an error
Syntax: number (errid)


Number = err. Number ‘returns the ID of the error
Err. Number = “C: \ test. TXT” ‘set the ID of error


Description: returns or sets the object (or application name) that reports the error
Syntax: source (string)


Source = err. Source ‘returns the object or application name of error
Err. Source = “box” ‘set the object or application name of error

Recommended Today

Collection splitting method sharing

Reprinted from: http://www.java265.com/JavaJingYan/202205/16533595033477.html   The following author describes the method of splitting a list collection into multiple small collections, as shown below Implementation ideas: Use the subList method from the list collection to split the collection into multiple sub-collections package com.java265.other; import java.util.ArrayList; import java.util.List; /* * Example sharing of list split * */ public […]