错误处理块中 Resume 和 Goto 之间的区别 [英] Difference between Resume and Goto in error handling block

查看:25
本文介绍了错误处理块中 Resume 和 Goto 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在以下示例中应使用 Resume 语句而不是 Goto 语句.

I understand that in the following example a Resume statement should be used instead of a Goto statement.

Sub Method()
  On Error Goto ErrorHandler
  ...
CleanUp:
  ...
  Exit Function

ErrorHandler:
  Log error etc

  Err.Clear  'Is this line actually necessary?'

  Resume CleanUp 'SHOULD USE THIS'
  Goto CleanUp  'SHOULD NOT USE THIS'
End Sub

我的问题是两者的执行有什么区别?

My question is what difference is there in the execution of the two?

推荐答案

两者都将执行转移到 Cleanup 标签.据我所知,唯一的区别是

Both transfer execution to the Cleanup label. As far as I can remember, the only differences are

  • 使用 Goto 不会清除 Err 对象(因此,如果您使用 Goto,则需要 Err.Clear)并留下错误处理程序禁用.如果在 Cleanup 标签之后发生错误,则不会在 ErrorHandler 处进行处理.
  • 使用 Resume 会清除 Err 对象并重新打开错误处理程序(在处理错误时它会被禁用).如果在 Cleanup 标签之后发生错误,将在 ErroHandler
  • 处处理
  • Using Goto doesn't clear the Err object (so Err.Clear is necessary if you use Goto) and it leaves your error handler disabled. If an error occurs after the Cleanup label, it won't be handled at ErrorHandler.
  • Using Resume clears the Err object and it switches your error handler back on (it is disabled while it is handling errors). If an error occurs after the Cleanup lable, it will be handled at ErroHandler

VB6 Resume 语句的手动输入 没有解释这些差异.

The VB6 manual entry for the Resume statement doesn't explain these differences.

这篇关于错误处理块中 Resume 和 Goto 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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