错误捕获不起作用 [英] error trapping not working
问题描述
在Winxp Pro上
我尝试捕获错误:
错误恢复下一次
If(Err.Number) <> 0)然后
结束子
结束如果
但不管是什么情况Err.Number = 0当我在win2k pro计算机上使用visual basic
6.0时,返回的错误值为0以外。
是否有我需要下载的补丁或者我是需要升级到VB.Net或
的东西吗?
aaron <在****** @ yahoo.com>在消息中写道
news:c4 ********** @ nntp6.u.washington.edu ...On Winxp Pro
我试图捕获一个错误:
错误恢复下一个
如果(Err.Number<> 0)那么
结束子
结束如果
但无论如何Err.Number = 0.当我在win2k pro计算机上使用visual basic
6.0时,返回的错误值为
0以外的值。是否有补丁我需要下载还是需要升级到VB.Net或
?
" resume next"意思是......继续下一个语句,这样它就不会发现错误(基本上你忽略了错误)。你可能想要什么
来捕捉错误可能是:
Sub SomeSub()
On Error GoTo ErrorHan
''可能产生错误的代码
退出Sub
错误地:
选择Case Err.Number''评估错误编号。
Case xx''处理它
Case''etc
End Select
简历
End Sub
2004年3月31日星期三02: 55:39 GMT,Raoul Watson
< Wa ***** @ IntelligenCIA.com>写道:
< snip>
" resume next"意思是......继续下一个语句所以它不会发现错误(基本上你忽略了错误)。您可能想要做什么来捕获错误可能是:
Sub SomeSub()
On Error GoTo ErrorHan
''代码可能会生成错误
退出Sub
错误汉:
选择案例Err.Number''评估错误编号。
案例xx''处理它
案例''等
结束选择
简历
Raoul,我完全不同意,两者都与你所说的关于
On Error Resume Next
和你''改进'的替代品
我建议你仔细检查On Error Resume Next
- 你会发现
a)它的工作原理
b)使用它会使代码更简单
到OP - 试试这个
私有子Command1_Click()
将我视为整数
错误恢复下一页
I = I / 0
如果错误那么MsgBox Err.Description
End Sub
>
谢谢,有了你的提示,我发现问题是错误没有传递给我的其他函数
。如果我想传递描述和
号码,如何传递错误对象或传递错误的最佳方法是什么?我有:
Sub SomeSub()
On Error Resume Next
''产生错误的代码
如果错误那么
MyError(错误)''传递错误对象????
结束如果
结束子
---------------------------
Sub MyError (MyErrorObject as ErrObject)
msgbox MyErrorObject.number''它始终为0,因为它没有被传递
End Sub
谢谢!
" J French" < ER ***** @ nowhere.com>在消息中写道
news:40 **************** @ news.btclick.com ...周三, 2004年3月31日02:55:39 GMT,Raoul Watson
< Wa ***** @ IntelligenCIA.com>写道:
< snip>
" resume next"意思是......继续下一个语句所以它不会发现错误(基本上你忽略了错误)。您可能想要捕获错误的
想要做什么:
Sub SomeSub()
错误GoTo ErrorHan
''代码可能会产生错误
退出Sub
错误汉:
选择案例Err.Number''评估错误编号。
案例xx''处理它
案例''等
结束选择
简历
Raoul,我完全不同意,两者都与你说的关于
On Error Resume Next
和你''改进'的替代品
我建议你仔细查看On Error Resume Next
- 你会发现
a)它的工作原理< b)使用它可以使代码更简单
对OP - 试试这个私有Sub Command1_Click()
Dim I As Integer
错误继续下一步
我= I / 0
如果错误然后MsgBox Err.Description
结束子
On Winxp Pro
I try to trap an error:
On error resume next
If (Err.Number <> 0) Then
End sub
End If
but no matter what the case Err.Number = 0. When I was using visual basic
6.0 on a win2k pro computer, errors were returned with values other than 0.
Is there a patch I need to download or do I need to upgrade to VB.Net or
something?
"aaron" <at******@yahoo.com> wrote in message
news:c4**********@nntp6.u.washington.edu...On Winxp Pro
I try to trap an error:
On error resume next
If (Err.Number <> 0) Then
End sub
End If
but no matter what the case Err.Number = 0. When I was using visual basic
6.0 on a win2k pro computer, errors were returned with values other than 0. Is there a patch I need to download or do I need to upgrade to VB.Net or
something?
"resume next" means exactly that.. continue with the next statement so it
can''t catch errors (basically you are ignoring errors). What you might want
to do to catch errors is probably:
Sub SomeSub()
On Error GoTo ErrorHan
''code which may generate error
Exit Sub
ErrorHan:
Select Case Err.Number '' Evaluate error number.
Case xx ''handle it
Case ''etc
End Select
Resume
End Sub
On Wed, 31 Mar 2004 02:55:39 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:
<snip>
"resume next" means exactly that.. continue with the next statement so it
can''t catch errors (basically you are ignoring errors). What you might want
to do to catch errors is probably:
Sub SomeSub()
On Error GoTo ErrorHan
''code which may generate error
Exit Sub
ErrorHan:
Select Case Err.Number '' Evaluate error number.
Case xx ''handle it
Case ''etc
End Select
Resume
Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your ''improved'' alternative
I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works
b) use of it makes simpler code
To the OP - try this
Private Sub Command1_Click()
Dim I As Integer
On Error Resume Next
I = I / 0
If Err Then MsgBox Err.Description
End Sub
Thanks, with your hints I found that the problem is the error is not being
passed to my other function. How do I pass an error object or what is the
best way to pass an error if I want to pass both the description and the
number? I have:
Sub SomeSub()
On Error Resume Next
''code that generates error
If Err Then
MyError(Err) ''pass error object????
End If
End Sub
---------------------------
Sub MyError (MyErrorObject as ErrObject)
msgbox MyErrorObject.number ''it is always 0 because it''s not being passed
End Sub
Thanks!
"J French" <er*****@nowhere.com> wrote in message
news:40****************@news.btclick.com...On Wed, 31 Mar 2004 02:55:39 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:
<snip>
"resume next" means exactly that.. continue with the next statement so it
can''t catch errors (basically you are ignoring errors). What you might wantto do to catch errors is probably:
Sub SomeSub()
On Error GoTo ErrorHan
''code which may generate error
Exit Sub
ErrorHan:
Select Case Err.Number '' Evaluate error number.
Case xx ''handle it
Case ''etc
End Select
Resume
Raoul, I totally disagree, both with what you say about
On Error Resume Next
and your ''improved'' alternative
I suggest that you check out On Error Resume Next very carefully
- you will find that
a) it works
b) use of it makes simpler code
To the OP - try this
Private Sub Command1_Click()
Dim I As Integer
On Error Resume Next
I = I / 0
If Err Then MsgBox Err.Description
End Sub
这篇关于错误捕获不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!