如何在VB6中处理错误处理程序中的错误? [英] How do you handle errors in error handlers in VB6?

查看:145
本文介绍了如何在VB6中处理错误处理程序中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私人子系统err1 

调用ProcessLargeBatch1
调用ProcessLargeBatch2
'...更多...'

退出子

err1:
调用清理'特定于DoSomething'
调用HandleError'常规错误处理:记录,消息框,...'

End Sub

清理过程有时会还原操作,回滚事务,删除临时文件等。在大多数情况下,此操作也可能失败。



在这种情况下我该怎么办?我将错误恢复下一步添加到错误处理程序中,但会删除现有的 Err 对象。将错误处理程序添加到清理也有同样的问题。



确保原始错误的最佳方法是什么?仍然被处理/记录?



编辑:另外一个问题是我也想通知用户错误。有时重要的是,清理发生得很快,我不希望消息框长时间阻止应用程序,并在用户确认错误后进行清理。

解决方案

首先,从您需要的Err对象中读取所有信息,即数字,描述等,然后清除错误并执行所需的操作。



更改您通知用户使用您已缓存的值的方式,而不是使用Err对象本身。


I frequently encounter this situation in my VB6 applications

Private Sub DoSomething

  On Error Goto err1

  Call ProcessLargeBatch1
  Call ProcessLargeBatch2
  '... more ...'

  Exit Sub

err1:
  Call Cleanup 'Specific for DoSomething'
  Call HandleError 'General error handling: Logging, message box, ...'

End Sub

The Cleanup procedure sometimes reverts actions, rolls back a transaction, deletes temporary files, and so on. In most cases this operation can also fail.

What do I do in this case? I'd add an On Error Resume Next into the error handler but that deletes the existing Err object. Adding an error handler to Cleanup has the same problem.

What is the best way to ensure that the original errors still gets processed/logged?

EDIT: One additional problem is that I also want to notify the user of the error. Sometimes it is important, that the cleanup happens fast and I don't want the message box block the application for a long time and do the cleanup after the user acknowledges the error.

解决方案

Firstly, read all the information out of the Err object that you will need, i.e. number, description, etc., then clear the error and do what you want.

Change the way you inform the user to use the values you have cached, and not to use the Err object itself.

这篇关于如何在VB6中处理错误处理程序中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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