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