Summary of On Error statements in VBScript
VBScript provides two statements and an object to handle "runtime errors", as shown in the following: 1.On Error Resume Next statement, 2.On Error Goto 0 statement, 3. err Object. Next we will discuss it in detail.
If you do not use the On Error statement, any running errors are fatal. That is to say, the result will display an Error message and stop running. An "Allowed" Error handler is a handler opened by the On Error statement, and an "active" Error handler is an Error handler allowed during Error handling.
On Error GoTo 0
Indicates disabling any started error handling programs in the current process.
On Error Resume Next
It indicates that when a running error occurs, the control forwards it to the statement after the wrong statement occurs, and continues to run here. This method is used to access objects without using On Error GoTo.
On Error GoTo line
Start the error handling program, and the routine starts from the line specified in the necessary line parameters. The line parameter can be any line label or line number. If a running error occurs, the control jumps to line to activate the error handler. The specified line must be in the same process as the On Error statement; otherwise, a compilation time Error occurs.
In general, if an Error is captured On the created object or control, you need to use On Error Resume Next to determine its Err. number. Handle the error according to the error type.
The following error-related code is provided:
?
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 see" & Err. Helpfile & "topic "&_ "The following HelpContext:" & Err. HelpContext MsgBox Msg, "error:" & Err. Description, Err. Helpfile, Err. HelpContext End If |
The above is all the content of this article. I hope you will like it.