VBS tutorial: method raise method

Time:2021-11-23

Raise method

Build runtime error

object.Raise(number, source, description, helpfile, helpcontext)

parameter

object

Should beErrObject.

Number

LongInteger subtype that identifies the nature of the error. VBScript errors (both VBScript defined and user-defined errors) range from 0 to 65535.

Source

Name the string expression of the object or application that initially generated the error. Use forms when setting this property for an automation objectproject.class。 If nothing is specified, the programming ID of the current VBScript project is used.

Description

String expression describing the error. If not specified, checknumberValue of. If you can map it to a VBScript runtime error code, use the string provided by VBScript as thedescriptionuse. If not withnumberIf the corresponding VBScript error, the general error message is used.

Helpfile

The full legal path of the help file where help information for this error can be found. If not specified, VBScript uses the full legal drive, path, and file name of the VBScript help file.

Helpcontext

Context ID, IDhelpfileTopics that provide error help in. If omitted, use andnumberProperty corresponds to the wrong VBScript help file context ID, if any.

explain

exceptnumberAll parameters other than are optional. If usedRaise, without specifying some parameters, andErrIf the property settings of the object contain values that are not cleared, these values will become incorrect values.

Set the error code in the automation objectnumberProperty to the constantvbObjectErrorAdd error code number. For example, to generate error number 1050, you cannumberProperty is assigned tovbObjectError + 1050 。

The following example illustrates how to useRaisemethod:

On error resume nexterr. Raise 6 'overflow error occurred. Msgbox ("error #" & CSTR (err. Number) & "" & err. Description) err. Clear 'clears the error.