Summary of On Error statements in VBScript

Source: Internet
Author: User

Summary of On Error statements in VBScript

VBScript provides two statements and an object to handle "runtime errors", as shown in the following: 1.On Error Resume Next statement, 2.On Error Goto 0 statement, 3. err Object. Next we will discuss it in detail.

If you do not use the On Error statement, any running errors are fatal. That is to say, the result will display an Error message and stop running. An "Allowed" Error handler is a handler opened by the On Error statement, and an "active" Error handler is an Error handler allowed during Error handling.

On Error GoTo 0

Indicates disabling any started error handling programs in the current process.

On Error Resume Next

It indicates that when a running error occurs, the control forwards it to the statement after the wrong statement occurs, and continues to run here. This method is used to access objects without using On Error GoTo.

On Error GoTo line

Start the error handling program, and the routine starts from the line specified in the necessary line parameters. The line parameter can be any line label or line number. If a running error occurs, the control jumps to line to activate the error handler. The specified line must be in the same process as the On Error statement; otherwise, a compilation time Error occurs.

In general, if an Error is captured On the created object or control, you need to use On Error Resume Next to determine its Err. number. Handle the error according to the error type.

The following error-related code is provided:

?

1

2

3

4

5

6

7

8

9

10

11

On Error Resume Next

Dim Msg

Err. Clear

Err. Raise 6 'generate "Overflow" error.

Err. Helpfile = "yourHelp. hlp"

Err. HelpContext = 5

If Err. Number <> 0 Then

Msg = "Press F1 or Help to see" & Err. Helpfile & "topic "&_

"The following HelpContext:" & Err. HelpContext

MsgBox Msg, "error:" & Err. Description, Err. Helpfile, Err. HelpContext

End If

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.