.net 什么是“第一次机会例外”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/564681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a "first chance exception"?
提问by Frederick The Fool
What exactly is a first chance exception? How and where does it originate in a .NET program? And why is it called by that peculiar name (what 'chance' are we talking about)?
究竟什么是第一次机会例外?它如何以及从哪里起源于 .NET 程序?为什么它被称为那个奇特的名字(我们在谈论什么“机会”)?
采纳答案by annakata
It's a debugging concept. Basically exceptions are thrown to the debugger firstand then to the actual program where if it isn't handled it gets thrown to the debugger a secondtime, giving you a chanceto do something with it in your IDE before and after the application itself. This appears to be a Microsoft Visual Studio invention.
这是一个调试概念。基本上抛出异常给调试器第一,然后到如果不处理它被扔在了调试器的实际程序第二的时候,给你一个机会,之前和应用程序本身后,用它做的东西在你的IDE。这似乎是 Microsoft Visual Studio 的发明。
回答by Ian G
First chance exception notifications are raised when an exception is thrown. Second chance notifications are when it is not caught. (Chance – as in opportunity to break into the code in the debugger).
抛出异常时会引发第一次机会异常通知。第二次机会通知是当它没有被捕获时。(机会 - 作为在调试器中闯入代码的机会)。
回答by codingatty
I just started using the debugger and ran into this. In my research, I found the MSDN blog post What is a First Chance Exception?that cleared it up for me.
我刚开始使用调试器并遇到了这个问题。在我的研究中,我发现了 MSDN 博客文章什么是第一次机会异常?这为我清除了它。
The big takeaways from the blog post for me are that it refers to notification to the debugger, and not something my code would necessarily need to handle, and most importantly, "First chance exception messages most often do not mean there is a problem in the code."
对我来说,这篇博文的主要内容是它指的是对调试器的通知,而不是我的代码必然需要处理的事情,最重要的是,“第一次机会异常消息通常并不意味着程序中存在问题。代码。”
回答by David
When an application is being debugged, the debugger gets notified whenever an exception is encountered. At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception.
在调试应用程序时,只要遇到异常,调试器就会收到通知。此时,应用程序被挂起,调试器决定如何处理异常。第一次通过此机制称为“第一次机会”异常。
Depending on the debugger's configuration, it will either resume the application and pass the exception on or it will leave the application suspended and enter debug mode. If the application handles the exception, it continues to run normally.
根据调试器的配置,它要么恢复应用程序并传递异常,要么将应用程序挂起并进入调试模式。如果应用程序处理异常,它会继续正常运行。
First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled.
第一次机会异常消息通常并不意味着代码中存在问题。对于优雅地处理异常的应用程序/组件,第一次机会异常消息让开发人员知道遇到并处理了异常情况。
回答by Agustin Garzon
From a developer's perspective, it's more concerning a second-chance exception, because it would mean it was not handled in code; therefore the application would stop.
从开发人员的角度来看,更多的是关于第二次机会异常,因为这意味着它没有在代码中处理;因此应用程序将停止。
First chance could be many of them, but the ones to concern about more, again, from a development perspective, are second chance, because it would lead to an application crash.
第一次机会可能有很多,但从开发的角度来看,需要更多关注的是第二次机会,因为它会导致应用程序崩溃。

