Summary of usage of On Error statement in VBScript

Source: Internet
Author: User
Tags goto

The VBScript language provides two statements and an object to handle "Run-time errors", such as the next, 1.On error Resume Next statement, 2.On error Goto 0 statement, 3.Err object, below we will discuss in detail.

If the On Error statement is not used, any run-time error is fatal, that is, the result will cause an error message to be displayed and the operation aborted. A "allowed" error handler is a handler that is opened by the On Error statement, and an "active" error handler is an error handler that is allowed during processing of the error.

On Error GoTo 0

Represents the prohibition of any initiated error handlers in the current procedure.

On Error Resume Next

Explains that when a run-time error occurs, the control goes to the statement immediately following the statement where the error occurred, and continues to run here. Use this form instead of on Error GoTo when accessing an object.

On Error GoTo Line

Starts the error handler, and the routine starts with the line specified in the necessary line arguments. The line argument can be any row label or line number. If a run-time error occurs, the control jumps to line and activates the error handler. The specified line must be in the same procedure as the on Error statement; Otherwise, a compile-time error occurs.

In general, if the object or control we create is incorrectly captured, you need to use On Error Resume Next, and then do the corresponding processing based on the error type in the Err.Number of the judgment.

Attach a section of the error-related code:

?

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" & ERR . Helpfile & "topic for" & _ "The following helpcontext:" & Err.helpcontext MsgBox Msg, "Error:" & ERR . Description, Err.HelpFile, Err.helpcontext end If

The above mentioned is the entire content of this article, I hope you can enjoy.

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.