第一次机会例外
我一直在浏览 MSDN 帮助文档来掌握 Visual Basic。 在尝试使用计时器 --one 的示例后,将标签和计时器组件拖到设计器中,并将以下内容添加到组件子例程
Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString
中调试期间立即窗口的输出如下
类型的第一次机会异常 发生“System.InvalidCastException” 在 Microsoft.VisualBasic.dll 中
第一个 类型的偶然异常 发生“System.InvalidCastException” 在 Microsoft.VisualBasic.dll 中
使用上下文菜单组件的先前 MSDN 示例中也会出现相同的错误。 我应该Try...Catch...Finally
这个错误并尝试继续吗? 或者,我正在处理更严重的事情吗?
've been running through the MSDN help documents to get a hang of Visual Basic. After trying out the example using timers --one drags a label and timer component into the designer and adds the following to the components subroutine
Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString
The output for the immediate window during debug is the following
A first chance exception of type
'System.InvalidCastException' occured
in Microsoft.VisualBasic.dll
A first
chance exception of type
'System.InvalidCastException' occured
in Microsoft.VisualBasic.dll
The same error occurs on a previous MSDN example using a context menu component. Should I Try...Catch...Finally
this error and try to move on? Or, am I dealing with something much more serious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 IDE 中尝试转到“工具”>“ 选项> 项目与解决方案> VB 默认值并将 Option Strict 设置为“On” - 这可能有助于在编译项目时而不是运行项目时发现转换问题。
“第一次机会执行”并不一定意味着您的代码有问题。 这可能意味着 IDE 或编译器或任何其他涉及的组件遇到并处理了错误,并且在此过程中调试器收到通知,并将异常报告到即时窗口。 这是关于该主题的优秀帖子:
http://blogs .msdn.com/davidklinems/archive/2005/07/12/438061.aspx
In the IDE try going to Tools > Options > Projects and Solutions > VB Defaults and setting Option Strict to 'On' - this may help catch casting problems when you compile your project rather than when you run it.
A 'first chance execption' does not necessarily mean you have a problem in your code. It could mean the IDE or the compiler or any other involved component encountered and handled an error and in the process the debugger is notified and the exception is being reported to the immediate window. This is an excellent post on the topic:
http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx
调试和诊断第一次机会异常的快速而简单的解决方案是:
然后
运行时期间的多个第一次机会异常可能会削弱应用程序的性能,因为异常处理的成本很高。 尤其是在网络应用程序中。 您可以添加此处理程序并查看特定的第一次机会异常并尝试避免/纠正它们。
A quick and easy solution for debug and diag of First Chance Exception is :
and then
Multiple First Chance Exception during the runtime can cripple the performance of your application because exception handling is expensive. Especially in web apps. You can add this handler and look at specific first chance exceptions and try to avoid/correct them.
当您看到有关第一次机会异常的信息时,这只意味着您调用的代码中捕获了异常,但并不一定意味着代码失败。 如果代码运行时不会导致程序崩溃并返回有效值,则没有问题。 当您实现自己的 try/catch 块时,您还将在调试窗口中看到有关首次机会异常的输出。
When you see something about a first chance exception, it only means that an exception was caught within the code you called but does not necessarily mean that the code failed. If the code runs without causing your program to crash and returns a valid value, then do not have a problem. You will also see output in the debug window about first chance exceptions when you implement your own try/catch blocks.
在调试菜单-> 异常,您可以使调试器在第一次抛出异常时停止,即使稍后会捕获它; 如果你想知道发生了什么,这是最简单的方法
In the Debug menu -> Exceptions, you can enable the debugger to stop when an Exception is first thrown, even if it would be caught later; if you want to find out what's happening, this is the easiest way to do it
在第一次出现异常时检查异常的详细信息。 您应该看到堆栈帧/跟踪属性。 在那里您应该看到错误发生在哪一行。 这应该对你有帮助。
In the first chance exception examine the details of the exception. You should see a stack frame/trace property. In there you should see what line the error occurs on. This should help you.