使用“on error resume next";在经典 ASP 中,以及如何处理错误 [英] using "on error resume next" in classic ASP, and how to handle errors

查看:53
本文介绍了使用“on error resume next";在经典 ASP 中,以及如何处理错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想问一下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

我想确保 UPDATE 运行良好,并且我想检查是否存在一些问题,因此我在代码中添加了调试功能,例如:

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

问题是:在循环过程中,如果遇到错误,下一个循环是否会出现错误(并因此再次触发错误块)?或 on error goto 0 将清除 Err 对象?换句话说,它会起到错误处理的作用吗?

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 重置 goto 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)

还有显式的err.clear().

这篇关于使用“on error resume next";在经典 ASP 中,以及如何处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆