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

查看:141
本文介绍了错误处理块中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 ,并且会使您的错误处理程序被禁用。如果清理标签之后发生错误,则不会在 ErrorHandler 处理。

  • 使用恢复清除Err对象,并重新打开错误处理程序(它在处理错误时被禁用)。如果在清理 lable之后发生错误,它将在 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 手动条目并不能解释这些差异。

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

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

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