Good day all, I would like to ask a thing about on error resume next
let\'s assume we have a loop to navigate through a recordset like:
Do w
on error resume next statement just only ignore the current line error and send the program control to the next line.
on error goto 0 just stops the working of on error resume next.That's it.
<%
on error resume next
response.write(1/0)
if err.number <> 0 then
response.write("<b>" & "err= "&"</b>")
response.write(err.description)
response.write("<b>" & " err number= "&"</b>" )
response.write(err.number&"</br>")
end if
'after this statement ASP will no longer resume the error and program terminate at here if error occur after this line
on error goto 0
response.write(6/0)
%>
The correct code to use is
Err.Clear
I have tested it with the following code
<%on error resume next
response.write (p(10))
Response.write(Err.Number)
response.write("<br>")
response.write(Err.description)
response.write("<br>")
Err.Clear
Response.write(Err.Number)
response.write("<br>")
response.write(Err.description)
response.write("<br>")
%>
And you can see the correct response is below, which shows the error being cleared
*13
Type mismatch
0*
VBScript resets the error on goto 0
:
on error resume next
i = 1 / 0
WScript.echo( err.number ) '' prints 11 (div by 0)
on error goto 0
WScript.echo( err.number ) '' prints 0 (no error)
There is also the explicit err.clear()
.