0

我想创建我的版本错误报告表单而不是默认错误窗口。

如何创建我的版本表单错误报告?

例如:

在此处输入图像描述

4

1 回答 1

1

所以你想在发生异常时调用自定义处理程序?没问题,只需在程序开头定义这 3 行神奇的行(作为 的第一行Sub Main):

AddHandler Application.ThreadException, AddressOf GenericHandler
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledHandler

然后定义 GenericHandler 和 UnhandledHandler,它们将调用您的自定义表单。

这是两个处理程序的示例实现:

Public Shared Sub GenericHandler(ByVal sender As Object, ByVal args As Threading.ThreadExceptionEventArgs)
  ReportException(args.Exception)
End Sub

Public Shared Sub UnhandledHandler(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
  If Not Debugger.IsAttached Then
    ReportException(args.ExceptionObject)
  End
End If

Public Shared Sub ReportException(ByVal ex As System.Exception)
  MsgBox(ex.ToString, MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation, "Unhandled exception - Please contact support")
  'you can further improve this to add custom logging etc.
End Sub
于 2013-02-05T15:03:55.917 回答