第一次机会异常 [英] A First Chance Exception

查看:371
本文介绍了第一次机会异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过MSDN帮助文档,我们一直在运行Visual Basic。在尝试使用定时器的示例之后 - 将标签和定时器组件拖放到设计器中,并将以下内容添加到组件子例程

  Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString 

直接窗口的输出调试是以下


类型
'System.InvalidCastException'的第一次机会异常在Microsoft.VisualBasic中发生
.dll



的第一个
机会异常
'System.InvalidCastException'在Microsoft.VisualBasic.dll中发生


在使用上下文菜单组件的以前的MSDN示例中发生相同的错误。应该我尝试... Catch ...最后这个错误,并尝试继续前进?或者,我正在处理更严重的事情?

解决方案

当您看到有关第一次机会异常的情况时,只意味着您所调用的代码中遇到了异常,但并不一定意味着代码失败。如果代码运行而不会导致程序崩溃并返回有效的值,那么没有问题。您还将在调试窗口中看到有关实现自己的try / catch块的第一次机会异常的输出。


'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?

解决方案

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.

这篇关于第一次机会异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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