VB6错误传播

标签 vb6 error-handling

我在主调用过程上使用错误处理程序,并让其他过程汇总到该错误处理程序。

我应该每次都清除错误吗?或者我应该 Exit Sub 而不是让错误处理程序在 End Sub 上继续?

我问这个问题是因为我读到我可能会捕获第一个错误,然后其他错误将不会被处理。

很抱歉,如果这不太清楚。不太确定我在说什么。

谢谢!!

编辑:类似这样的事情。有这个必要吗?

Public Sub SubA()
On Error Goto ProcError

  ' other code  
  MsgBox FuncA()

ProcExit:  
  Exit Sub

ProcError:  
  MsgBox Err.Description  
  Resume ProcExit
End Sub

最佳答案

OP:我应该每次都清除错误吗?或者我应该 Exit Sub 而不是让错误处理程序在 End Sub 上继续?

清除错误是什么意思?
通常程序是这样写的

public sub myProcedure()
on error goto e:
'statements that could raise error
exit sub

e:
Log err.Number, err.Description, "error occurred in myProcedure"
end sub

或者

您可以选择不添加错误处理程序。在这种情况下,错误将传播到调用者(或处理错误的过程)。

请发布您想要实现的目标和期望的示例代码。

编辑:这是您发布的代码的含义

Public Sub SubA()
On Error Goto ProcError

  ' other code  
  MsgBox FuncA()
exit sub   'put exit sub otherwise it will execute the line below, even if no error

ProcExit:  
'this statement will get executed after the error msgbox is shown
msgbox "Reached ProcExit"
Exit Sub

ProcError:  
MsgBox Err.Description  'catch the error and show the msgbox
'error is cleared the point it reaches ProcError
'Resume ProcExit acts as goto, to execute any statements after the error is handled
Resume ProcExit 
End Sub

关于VB6错误传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1376964/

相关文章:

javascript - JavaScript 控制台中的 GET 错误是什么?

sql-server - 如何在SQL 2008 R2中记录警告(严重性错误)

winforms - 在 Visual Studio 2010 中缺少 VB6 的 shift-click 添加工具箱项

vb.net - 从 .Net COM DLL 调用 VB6 表单?

c# - 将 vb6 类型转换为 VB.net 或 C# 结构

Java/Eclipse - 在主方法之外使用 BufferedReader 时解决 IOException

javascript - RxJS 在 Ajax 错误后继续监听

VB6 ADO 连接池

vb6 - 在 VB6 中为工具栏控件创建键盘快捷方式

php - 使用Symfony 2.3引发PHP通知异常