1. On Error Statement
The purpose of this statement is to enable or disable the error handler. The general usage is as follows:
On Error Resume Next On Error GoTo 0 |
If the On Error Resume Next statement is not used in your code, the runtime error will display an error message and the execution of the code will be terminated.
But when you adopt it, the program will continue to execute as the statement after the error statement, or as the statement in the most recent process called (which contains the On Error Resume Next statement). This statement can continue to execute the program regardless of runtime errors, and then you can establish an error handling routine inside the process.
When another procedure is called, the On Error Resume Next statement becomes inactive. Therefore, if you want to perform internal error handling in a routine, you should execute the On Error Resume Next statement in each called routine.
If you have enabled the On Error Resume Next error handler, you can use On Error GoTo 0 to disable the error handler.
[Ctrl+A All selections are given for copying: you can modify some codes first, and then click Run]
Note: To generate a runtime error in the code, use the Raise method of the Err object.
This situation is often seen when debugging programs, for example, debugging the following two programs separately will be displayed.
1, err1.asp
| <%Err.Raise 6%> |
| Technical information (for support staff) Error Type: Microsoft VBScript Runtime Error (0x800A0006) overflow |
2, err2.asp
| <%cnbruce.com%> |
It's also the debugging process
| Technical information (for support staff) Error Type: Microsoft VBScript Runtime Error (0x800A01A8) Missing object: 'cnbruce' |
But when you add On Error Resume Next to the first line, you find that there is no error message, indicating that the internal error handling is completed.
But when the following procedures are performed, it is found
3, err3.asp