VBS Tutorial: VBscript statement-On Error statement

Source: Internet
Author: User

On Error statement

Enable or disable the error handling program.

On Error Resume Next
On Error GoTo 0

Description

If it is not used in your codeOn Error Resume NextThe error message is displayed when a running error occurs, and the execution of the Code is terminated. However, the specific operation is determined by the host that runs the code. The host can sometimes handle various types of errors selectively. In some cases, it can activate the script debugger where an error occurs. In other cases, because the host cannot notify the user, the error is not explicitly stated. How to handle errors depends entirely on the host's functions.

In any special process, as long as the error handler is enabled in the place where the stack is called, the errors will not be fatal. If the local error handler is not enabled in a process, when an error occurs, the control can be transferred through the stack call until a process with an error handler is found, and handle the error in the error. If the error handler is not found during the stack call process, the error message is displayed in the error area, the code execution is terminated, or the error is correctly handled by the host.

On Error Resume NextThe program will continue to execute the statement after the wrong statement is generated, or follow the last called process (this process containsOn Error Resume NextStatement. This statement can continue to execute the program regardless of running errors. Then, you can establish an error handling routine within the process. When calling another process,On Error Resume NextThe statement becomes inactive. Therefore, if you want to handle internal errors in the routine, you should executeOn Error Resume NextStatement.

When calling another process, do not useOn Error Resume NextSo if you want to embed an error handler in a routine, you must executeOn Error Resume NextStatement. When exiting a process, the error handler can be restored to its status before it enters the exited process.

If you have enabled the On Error Resume Next Error handler, you can use On Error GoTo 0 to disable the handler.

The following example illustrates how to use the On Error Resume Next statement:

On Error Resume NextErr.Raise 6  'Overflow error.MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)Err.Clear    'Clear the error.

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.