The VBScript language provides two statements and an object to handle "Run-time errors", such as the next, 1.On error Resume Next statement, 2.On error Goto 0 statement, 3.Err object, below we will discuss in detail.
If the On Error statement is not used, any run-time error is fatal, that is, the result will cause an error message to be displayed and the operation aborted. A "allowed" error handler is a handler that is opened by the On Error statement, and an "active" error handler is an error handler that is allowed during processing of the error.
On Error GoTo 0
Represents the prohibition of any initiated error handlers in the current procedure.
On Error Resume Next
Explains that when a run-time error occurs, the control goes to the statement immediately following the statement where the error occurred, and continues to run here. Use this form instead of on Error GoTo when accessing an object.
On Error GoTo Line
Starts the error handler, and the routine starts with the line specified in the necessary line arguments. The line argument can be any row label or line number. If a run-time error occurs, the control jumps to line and activates the error handler. The specified line must be in the same procedure as the on Error statement; Otherwise, a compile-time error occurs.
In general, if the object or control we create is incorrectly captured, you need to use On Error Resume Next, and then do the corresponding processing based on the error type in the Err.Number of the judgment.
Attach a section of the error-related code:
|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" & ERR . Helpfile & "topic for" & _ "The following helpcontext:" & Err.helpcontext MsgBox Msg, "Error:" & ERR . Description, Err.HelpFile, Err.helpcontext end If|
The above mentioned is the entire content of this article, I hope you can enjoy.