尝试捕获和恢复 [英] Try catch and Resume
问题描述
Hello All,
虽然,我已经阅读了使用Try Catch Block
而不是On error goto的所有优点,我是仍然困惑什么是替代的
classic" Resume"声明。 "简历"这是
调试中的关键行之一,它让VB程序员去了确定行,错误是
抛出。
我仍然使用错误goto而不是try catch,我想要恢复
进行调试。还有其他选择,比如VB.net中的Resume for Try
catch block?
最好的问候,
Pravin >
我真的不明白你想说什么。您可以使用Try Catch调试.NET中的
行错误。每当出现错误时,在Try
块中,它将被抛入catch语句中同样的尝试或任何上层
级别的捕获。如果你做下面这样的事情...
尝试
''陈述
Catch(Exception ex)
''ex.Tostring()< - 将为您提供错误所在的行号。
这是假设您遵守
调试模式
结束尝试
希望我已经解释了你要找的东西..
VJ
Neo < PR ********* @ gmail.com>在消息中写道
news:11 ********************** @ v46g2000cwv.googlegr oups.com ...大家好,
虽然,我已经阅读了使用Try Catch Block
而不是On error goto的所有优点,但我仍然感到困惑的是<替代
classic简历声明。 "简历"调试中的关键行之一就是让VB程序员去了错误被抛出的确切行。
我仍然使用错误goto而不是try catch,因为我想要恢复
进行调试。在VB.net中有什么替代方案可以尝试
catch块吗?
最好的问候,
Pravin
>
Resume允许代码在处于错误状态时继续。这允许程序员尝试纠正问题并继续。
我会
建议嵌套try catch finally语句让你到达你想要的地方
去。
给出:
On Error Resume Next
dim iRet as long
iRet = objTemp.Blowup
如果Err.number<> 0或iRet<> 0然后
err.clear
更正状态并继续前进
结束如果
成为:
dim iRet为整数
尝试
尝试
iRet = objTemp .Blowup
catch SpecificException1
''已知预期异常#1
catch SpecificException2
''已知预期异常#2
赶上ex例外
''意外异常且可能无法恢复
抛出新的applicationexception(不可纠正的错误条件>
发生。)
最后
''使用此块恢复你可以获得的东西
结束尝试
''继续使用你的逻辑
catch ex ex exception
''日志异常
''通知用户界面
''清理
结束尝试
" Neo" < PR ********* @ gmail.com>在消息中写道
news:11 ********************** @ v46g2000cwv.googlegr oups.com ...大家好,
虽然,我已经阅读了使用Try Catch Block
而不是On error goto的所有优点,但我仍然感到困惑的是<替代
classic简历声明。 "简历"调试中的关键行之一就是让VB程序员去了错误被抛出的确切行。
我仍然使用错误goto而不是try catch,因为我想要恢复
进行调试。在VB.net中有什么替代方案可以尝试
catch块吗?
最好的问候,
Pravin
>
"新" < PR ********* @ gmail.com> schrieb:虽然,我已经阅读了使用Try Catch Block
而不是On error goto的所有优点,但我仍然感到困惑什么是
classic的替代方案;简历和QUOT;声明。 "简历"是调试中的关键行之一,它让VB程序员去了错误被抛出的确切行。
不幸的是没有直接的相当于''Resume''可用。你会得到
必须把每一行都放到一个单独的''Try ... Catch''块中,以便
达到类似的行为。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
Hello All,
Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one of the crucial line in
debugging which let VB programmers go to exact line where error was
thrown.
I still use on error goto instead of try catch since, I want "Resume"
for debugging. Is there any alternative like Resume in VB.net for Try
catch block?
Best Regards,
Pravin
I really don''t understand what you are trying to say. You can debug to the
line of error in .NET with Try Catch.. Whenever there is a error, in a Try
block, its thrown into the catch statement in the same try or in any upper
level catch. If you do something like below...
Try
'' statements
Catch ( Exception ex)
'' ex.Tostring() <- will give you the line number where the error was..
This is assuming you complied in
debug mode
End try
Hope I have explained what you are looking for..
VJ
"Neo" <pr*********@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...Hello All,
Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one of the crucial line in
debugging which let VB programmers go to exact line where error was
thrown.
I still use on error goto instead of try catch since, I want "Resume"
for debugging. Is there any alternative like Resume in VB.net for Try
catch block?
Best Regards,
Pravin
Resume allowed the code to continue while in an error state. This allowed
the programmer to attempt to correct the problem and continue on. I would
propose nested try catch finally statements to get you where you would like
to go.
given:
On Error Resume Next
dim iRet as Long
iRet = objTemp.Blowup
if Err.number <> 0 or iRet <> 0 then
err.clear
correct the state and move on
end if
becomes:
dim iRet as integer
try
try
iRet = objTemp.Blowup
catch SpecificException1
''Known expected exception #1
catch SpecificException2
''Known expected exception #2
catch ex as exception
''Unexpected exception and potentially unrecoverable
throw new applicationexception("An uncorrectable error condition
occured.")
Finally
''Use this block to recover what you can
end try
''continue on with your logic
catch ex as exception
''Log exception
''Notify UI
''Clean up
end try
"Neo" <pr*********@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...Hello All,
Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one of the crucial line in
debugging which let VB programmers go to exact line where error was
thrown.
I still use on error goto instead of try catch since, I want "Resume"
for debugging. Is there any alternative like Resume in VB.net for Try
catch block?
Best Regards,
Pravin
"Neo" <pr*********@gmail.com> schrieb:Although, I have read all the advantages of using Try Catch Block
instead of "On error goto", I am still confused what is alternative for
classic "Resume" statement. "Resume" was one of the crucial line in
debugging which let VB programmers go to exact line where error was
thrown.
Unfortunately there is no direct equivalent for ''Resume'' available. You''ll
have to put every single line into a separate ''Try...Catch'' block to
archieve similar behavior.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于尝试捕获和恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!