Visual Studio不会在Form_Load事件中的异常中断

时间:2009-10-26 10:47:13

标签: .net visual-studio exception debugging

我最近将我的笔记本电脑从安装了Visual Studio 2005/2008的Vista 32bit更新到安装了Visual Studio 2008的Windows 7 x64。所以我不知道这是一个“Windows 7”问题还是仅仅是visual studio中的一个配置。

我的问题是Form_Load()事件中的exeptions被吞没而没有通知我,这使得调试错误变得更加困难,因为有时我甚至没有注意到发生异常。

假设我有这段代码(代码是VB.NET但是注释C#样式,因为语法荧光笔不能识别'作为注释符号)

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Load
    // Outside the Debugger the exception triggers the default
    // "Unhandled Exception" Dialog which is correct.
    // Withing 2008 IDE the debugger doen not break like it
    // should. However the exception still occures because
    // this text is printed to the Output Window:
    // A first chance exception of type 'System.Exception'
    // occurred in ExceptionTest.exe
    Throw New Exception("This Exception gets swallowed")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
    // This exception causes the Debugger to break at this line
    Throw New Exception("This Exception works fine")
End Sub

End Class

我找到了一个建议来检查例外对话框中的“抛出”复选框(“CTRL + D,E”)。 如果我这样做,调试器会在我想要的时候在Form_Load()异常处中断,但它也会在每个处理的异常时中断,例如:

Try
   DoSmthThatThrowsArgumentException() // Debugger breaks here
Catch ex as ArgumentException
   LogWriter.Write(ex.ToString())
End Try

任何人都有一个clou如何配置VS2008调试器在Form_Load()事件中表现正常?根据{{​​3}},看起来这是视觉工作室2008突然发生的事情。

0 个答案:

没有答案
相关问题