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 while not rs.EOF
query = "UPDATE ...."
conn.execute(query)
rs.movenext
loop
i would like to be sure the UPDATE
is going good, and i would like to check if there is some problems, so I have put a debugging features in the code like:
Do while not rs.EOF
query = "UPDATE ...."
on error resume next
conn.execute(query)
If Err.Number <> 0 Then
Response.write(Err.Number)
response.write("<br>")
response.write(Err.description)
response.write("<br>")
response.write(query)
response.write("<br><br>")
end if
on error goto 0
rs.movenext
loop
the question is : during a loop, if it encounters an error, the next cycle will the error be there (and so triggers again the error block) ? or on error goto 0
will clear the Err object?
in other words, will it works as a error handling?
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()
.
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*
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)
%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With