【问题标题】:UI thread exception handler is ignored during debug sessionUI 线程异常处理程序在调试会话期间被忽略
【发布时间】:2023-03-27 21:33:01
【问题描述】:

在桌面应用程序中我设置了琐碎

如果有人想要codez(那里没什么有趣的):

Namespace My

    Partial Friend Class MyApplication

        ' Thread exception handler. Handles all unhandled exceptions on UI thread.
        Private Sub UIThreadException(sender As Object, e As ThreadExceptionEventArgs)
            CustomErrorHandler.Handle(e.Exception, "[UIThreadException]")
        End Sub

        ' Handle the UI exceptions by showing a dialog box, and asking the user whether
        ' or not they wish to abort execution.
        ' NOTE: This exception cannot be kept from terminating the application - it can only 
        ' log the event, and inform the user about it. 
        Private Sub CurrentDomain_UnhandledException(sender As Object,
                                                     e As UnhandledExceptionEventArgs)
            Try
                Dim ex As Exception = CType(e.ExceptionObject, Exception)
                CustomErrorHandler.OnUnhandled(ex)
            Catch exc As Exception
                MsgBox(exc.ToString(), vbCritical, "Last resort error printout")
            End Try
        End Sub

    End Class

End Namespace

有时,当我从Form1ButtonOK_Click(...) 事件处理程序中抛出异常时会有所不同:

  • 当作为独立启动 (app.exe) 时,UIThreadException() 会按预期调用
  • 当从 Visual Studio (app.vshost.exe) 内部启动时,CurrentDomain_UnhandledException() 被调用在同一场景中(代码中与之前相同的位置,相同的数据),忽略 UIThreadException()处理程序

所以在独立的 exe 中,所有的工作都可靠,但在调试会话期间,在相同的情况下陷入未处理的异常是非常烦人的。

我可以在 Visual Studio 2012 和 2015 中观察到相同的行为。如果在简单的示例上进行测试,它在调试会话中也总是能按预期工作。如果代码更复杂(嵌套调用中引发的异常等),则 UI 线程异常处理程序将被忽略。

你们中是否有人能够观察到同样的问题并找到解决方案?

【问题讨论】:

    标签: vb.net visual-studio-2012 exception-handling visual-studio-2015 .net-3.5


    【解决方案1】:

    在 OnLoad() 事件中抛出了异常(我没有注意到)。

    一些没有经验的同事将 SQL 处理放入 OnLoad 事件处理程序而不是构造函数或 OnShow 事件处理程序。 And this is where troubles begin.是的,我曾经去过那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-28
      • 2011-04-16
      • 2015-12-10
      • 2015-02-02
      • 2016-01-10
      • 1970-01-01
      • 2018-04-01
      • 2011-08-17
      相关资源
      最近更新 更多