◎ Vbs Script Programming concise tutorial 5-error handling

Source: Internet
Author: User

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/jinghaianlange/archive/2007/07/16/1693676.aspx

 

There are many causes of errors. For example, if you enter a value of the error type, or the script cannot find the required file, directory, or drive, we can use Loop Technology to handle errors, however, vbs also provides some basic technologies for error detection and handling.

1. The most common error is a runtime error. That is to say, an error occurs when the script is running. It is the result of the script trying to perform illegal operations. For example, zero is used as the divisor. In vbs, any running errors are fatal. In this case, the script stops running and an error message is displayed on the screen. You can add

On Error resume next

This line of statements tells vbs to skip the wrong statement at runtime, and then execute the statement following it.

When an error occurs, this statement pushes the error code, description, and source code into the error stack.

2. Although on error resume

The next statement can prevent the vbs script from stopping when an error occurs, but it cannot really handle the error. To handle the error, you must add some statements to the script, it is used to check error conditions and process them when an error occurs.

VBScript provides an object ERR Object. It has two methods: Clear, raise, and five attributes: Description, helpcontext, helpfile, number, and source.

The ERR Object can be used directly without instance reference. For example:

On Error resume next

A = 11

B = 0

C = A/B

If err. Number <> 0 then

Wscript. Echo err. Number & err. Description & err. Source

End if

 

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.