简体   繁体   English

类模块中断与未处理错误中断(VB6错误捕获,IDE中的选项设置)

[英]Break in Class Module vs. Break on Unhandled Errors (VB6 Error Trapping, Options Setting in IDE)

Basically, I'm trying to understand the difference between the "Break in Class Module" and "Break on Unhandled Errors" that appear in the Visual Basic 6.0 IDE under the following path: 基本上,我试图理解Visual Basic 6.0 IDE中以下路径中出现的“Break in Class Module”和“Break on Unhandled Errors”之间的区别:

Tools --> Options --> General --> Error Trapping

The three options appear to be: 这三个选项似乎是:

  • Break on All Errors 打破所有错误
  • Break in Class Module 打破课堂模块
  • Break on Unhandled Errors 打破未处理的错误

Now, apparently, according to MSDN, the second option (Break in Class Module) really just means "Break on Unhandled Errors in Class Modules". 现在,显然,根据MSDN,第二个选项(Break in Class Module)实际上只是意味着“打破类模块中未处理的错误”。 Also, this option appears to be set by default (ie: I think its set to this out of the box). 此外,此选项似乎默认设置(即:我认为它设置为开箱即用)。

What I am trying to figure out is, if I have the second option selected, do I get the third option (Break on Unhandled Errors) for free? 我想弄清楚的是,如果我选择了第二个选项,我是否可以免费获得第三个选项(Break on Unhandled Errors)? In that, does it come included by default for all scenarios outside of the Class Module spectrum? 那么,它是否默认包含在类模块频谱之外的所有场景中? To advise, I don't have any Class Modules in my currently active project. 建议,我目前活跃的项目中没有任何类模块。 I have .bas modules though. 我有.bas模块。 Also, is it possible that by Class Mdules they may be referring to normal .bas Modules as well? 另外,是否有可能通过Class Mdules他们可能也指正常的.bas模块? (this is my second sub-question). (这是我的第二个子问题)。

Basically, I just want the setting to ensure there won't be any surprises once the exe is released. 基本上,我只是希望设置确保exe释放后不会有任何意外。 I want as many errors to display as possible while I am developing, and non to be displayed when in release mode. 我希望在开发时尽可能多地显示错误,并且在处于释放模式时不显示。 Normally, I have two types of On Error Resume Next on my forms where there isn't explicit error handling, they are as follows: 通常,我的表单上有两种类型的On Error Resume Next,没有明确的错误处理,它们如下:

On Error Resume Next ' REQUIRED On Error Resume Next ' NOT REQUIRED 在错误恢复接下来'必须在错误恢复接下来'不是必需的

The required ones are things like, checking to see if an array has any length, if a call to its UBound errors out, that means it has no length, if it returns a value 0 or more, then it does have length (and therefore, exists). 所需要的是,检查一个数组是否有任何长度,如果调用它的UBound错误,这意味着它没有长度,如果它返回值0或更多,那么它确实有长度(因此,存在)。 These types of Error Statements need to remain active even while I am developing. 即使在我开发过程中,这些类型的错误语句也需要保持活动状态。 However, the NOT REQUIRED ones shouldn't remain active while I am developing, so I have them all commented out to ensure that I catch all the errors that exist. 但是,在我开发的过程中,不需要的那些不应该保持活动状态,因此我将它们全部注释掉以确保我能够捕获所有存在的错误。

Once I am ready to release the exe, I do a CTRL+H to find all occurrences of: 一旦我准备好释放exe,我会按CTRL + H查找所有出现的:

'On Error Resume Next ' NOT REQUIRED '错误继续下一步'不需要

(You may have noticed they are commented out)... And replace them with: (您可能已经注意到它们被注释掉了)......并将它们替换为:

On Error Resume Next ' NOT REQUIRED On Error Resume Next'不需要

... The uncommented version, so that in release mode, if there are any leftover errors, they do not show to users. ...未注释的版本,因此在发布模式下,如果有任何剩余错误,它们不会向用户显示。

For more on the description by MSDN on the three options (which I've read twice and still don't find adequate) you can visit the following link: 有关MSDN对三个选项的描述的更多信息(我已阅读两次但仍然找不到),您可以访问以下链接:

http://webcache.googleusercontent.com/search?q=cache:yUQZZK2n2IYJ:support.microsoft.com/kb/129876&hl=en&lr=lang_en%7Clang_tr&gl=au&tbs=lr:lang_1en%7Clang_1tr&prmd=imvns&strip=1 http://webcache.googleusercontent.com/search?q=cache:yUQZZK2n2IYJ:support.microsoft.com/kb/129876&hl=en&lr=lang_en%7Clang_tr&gl=au&tbs=lr:lang_1en%7Clang_1tr&prmd=imvns&strip=1

I'm also interested in hearing your thoughts if you feel like volunteering them (and this would be my tentative/totally optional third sub-question, that being, your thoughts on fall-back error handling techniques). 我也有兴趣听你的想法,如果你想做志愿者(这将是我的暂定/完全可选的第三个子问题,那就是你对后备错误处理技术的想法)。

Just to summarize, the first two questions were, do we get option 3 included in all non-class scenarios if we choose option 2? 总结一下,前两个问题是,如果我们选择选项2,我们是否将选项3包含在所有非类场景中? And, is it possible that when they use the term "Class Module" they may be referring to .bas Modules as well? 而且,当他们使用术语“类模块”时,它们可能也指的是.bas模块吗? (Since a .bad Module is really just a class module that is pre-instantiated in the background during start-up). (因为.bad模块实际上只是一个在启动期间在后台预先实例化的类模块)。

Thank you. 谢谢。

I'll start with the first option. 我将从第一个选项开始。 Break on all errors simply disables your error handlers. 中断所有错误只会禁用错误处理程序。 This is useful when you are attempting to debug after you've put in error handlers, because you can have errors in the handlers themselves, or you can lose track of where the error happened when the error bubbles up the containership heirarchy (errors that aren't handled in a procedure attempt to find a handler in a calling procedure, which can be confusing if you're trying to find the offending line of code). 当您在输入错误处理程序后尝试进行调试时,这非常有用,因为您可能在处理程序本身中存在错误,或者当错误冒泡容器层数时,您可能会忘记错误发生的位置(错误不是在一个过程中处理尝试在调用过程中找到一个处理程序,如果你试图找到有问题的代码行,这可能会让人感到困惑。

Next, break on unhandled errors doesn't actually break in a class module if there is a line of code causing an error in there. 接下来,如果存在导致错误的代码行,则未处理错误的中断实际上不会在类模块中中断。 If you have this option set, and you call a method in a class, and there's an error in the line of code in the method, you'll break on the line in your client that has the method call. 如果您设置了此选项,并且在类中调用方法,并且方法中的代码行中存在错误,那么您将在客户端中具有方法调用的行中断。

Break in class module goes to the line of code in the class that has the error. 类模块中的中断转到具有错误的类中的代码行。 A caveat to this is that if you are working with an ActiveX EXE, the controlling setting is in its project rather than in the client project. 需要注意的是,如果您使用的是ActiveX EXE,则控制设置位于其项目中而不是客户端项目中。 That is, you can have break on all errors set in your client project, and break on unhandled errors set in your ActiveX EXE project, and you won't break in the class module because you are working with two separate processes. 也就是说,您可以中断客户端项目中设置的所有错误,并中断ActiveX EXE项目中设置的未处理错误,并且您不会在类模块中中断,因为您正在使用两个单独的进程。

I prefer personally to leave it set on break in class module, because it lets me drill down to the site of the error with greatest precision. 我个人更喜欢将它设置为类模块中的break,因为它允许我以最精确的方式深入到错误的站点。 This is before I start doing error handlers, though; 这是在我开始做错误处理程序之前; at that point I generally bounce around all three, depending on what I'm trying to stabilize. 在那一点上,我通常会在这三个方面反弹,这取决于我想要稳定的东西。

Finally, I do NOT recommend EVER using On Error Resume Next except in the context of inline error handling. 最后,除了在内联错误处理的上下文中,我不建议使用On Error Resume Next。

Yes, when you select "Break in class module", it DOES still break on unhandled errors, but it will also break on ANY errors in class modules (not plain modules) that aren't handled in the class module itself. 是的,当你选择“Break in class module”时,它仍会打破未处理的错误,但它也会破坏类模块本身未处理的类模块(不是普通模块)中的任何错误。

Contrast this to "break on unhandled errors" which will cause it to exit out of the class/user control code when an error occurs inside it making it difficult to track down the exact location. 将此与“打破未处理的错误”进行对比,这将导致它在类中发生错误时退出类/用户控制代码,从而难以追踪确切的位置。

It's probably best to leave it set on the "break on unhandled errors" for general development as the others WILL get annoying when you have handled errors that are benign. 对于一般开发而言,最好将其置于“未处理错误的中断”上,因为当您处理好的错误时,其他人会感到烦恼。 Note that it's best to try and detect these before they trigger an error though. 请注意,最好在它们触发错误之前尝试检测这些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM