第一次机会例外

Nig*_*ker 19 vb.net visual-studio windows-7

我有一个在windows xp下运行完美的项目.

现在我试图在Windows 7下运行它,并在立即窗口下得到了很多例外.

A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentException' occurred in LP_Wizard.exe
A first chance exception of type 'System.NullReferenceException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
Run Code Online (Sandbox Code Playgroud)

知道Microsoft.VisualBasic.dll在Windows 7中有什么问题 以及我如何纠正这个问题?

非常感谢您的帮助.

Mar*_*rén 57

如果要确定异常发生的位置,可以选择Debug-> Exceptions菜单项,并在出现的对话框中选中"Common Language Runtime Exceptions"的第一个复选框.这将使调试器在发生异常时立即中断,而不是仅在未处理的异常中断.

这也是为什么捕获一般异常通常是一个坏主意的一个原因,除非您明确记录捕获的信息.


Adr*_*ark 44

发生的事情是调试器可以在任何catch块被触发之前立即"看到"异常(因此是"第一次机会").任何未被catch块处理的异常都被视为"第二次机会"异常并将正常破坏.

如果这些异常没有停止运行您的应用程序,因为它们未处理,那么您可能没问题.大多数情况下,代码处理异常,这不是问题.输出只是Visual Studio,让您知道引发的异常.

如果有太多要忽略的话,请参阅" 安全处理异常时避免第一次机会异常消息 "的问题.

  • +1.此外,如果您触发了很多异常并捕获并忽略它们,那么可能值得尝试重写代码以避免它,因为它会表现得更好.例如,在调用之前使用if(thing!= null)而不是之后使用catch(NullPointerException). (6认同)