2013-02-05 37 views
0

我想創建我的版本錯誤報告窗體,而不是默認錯誤窗口。作出錯誤窗口

我如何創建我的版本表單錯誤報告?

例如:

enter image description here

回答

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 
+1

+1這一切,而我一直在周圍到處都是我的嘗試捕捉代碼! – AbZy

+0

坦克你非常, –

+0

@KazemFallahi:如果我的回答很有幫助,請考慮接受和/或upvoting它。 – Neolisk