In Vbscript, error handling is done using on Error Resume Next. If you add this sentence to your code, and if any errors occur in other code after this sentence, the system will ignore them and run the rest of the code. In the meantime, we can use the following code to catch errors.
this catches the error code and the description of the error and writes to the log file. However, the problem is that the code after we caught the error, if the error occurs again and you don’t catch it, the code will still ignore the error and continue to run. Ignoring errors is an undesirable result and can make debugging difficult. At this point, the sentence “On Error GoTo 0” can be used to terminate the previous Error handling, that is, it can be paired with “On Error Resume Next”. This will not affect the rest of the code.
has several characteristics to understand,
, 1 on error resume Next if defined in the global, the effect is global, you use this phrase in the main program, the back if the call a function, so if there is an error in the function, also will be ignored, behind the function call statements in your main program can also capture the error, this can be through the following simple code validation:
The result of executing the above code:
13 – type が consistent し ま せ ん.
main ….
As you can see, aaaaaaaaaaa was a deliberate error in the function, followed by wscript.echo “Funcb OK” and the following code were not executed. However, wscript.echo “main…” in the main program The statement is executed. That is, if a statement in a function is wrong, none of the subsequent statements in the function are executed, and the statement following the call to the function is executed directly.
2, On Error Resume Next If defined in the function, see the following code execution
execution results are as follows:
funcb ok
13 – type が consistent し ま せ ん.
13 – type が consistent し ま せ ん.
main ….
It can be seen that this error can be caught in the Err object inside the function and in the main program that calls it. This indicates that the Err object is global, so it should be understood that the scope of err is valid between an On Error Resume Next statement and an On Error Goto 0. If we add an invalid statement after the funcb call statement, the error MSG box will pop up, indicating that the On Error Resume Next in the function body cannot be applied outside of the function.
These are some of the experiences of using On Error Resume Next. If you understand the above two points, you can better use the error handling functions.
http://blog.csdn.net/zmxj/archive/2009/02/24/3932065.aspx
Reference: http://www.meizi.cn/article.asp?id=4