Imports System.Threading Public Class Program _ Shared Sub Main() ' ThreadExceptionƒCƒxƒ“ƒgEƒnƒ“ƒhƒ‰‚ð“o˜^‚·‚é AddHandler Application.ThreadException, AddressOf Application_ThreadException ' UnhandledExceptionƒCƒxƒ“ƒgEƒnƒ“ƒhƒ‰‚ð“o˜^‚·‚é AddHandler Thread.GetDomain().UnhandledException, AddressOf Application_UnhandledException ' ƒƒCƒ“EƒXƒŒƒbƒhˆÈŠO‚Ì—áŠO‚ÍUnhandledException‚Ńnƒ“ƒhƒ‹‚·‚é 'Dim buffer As String = "1" 'Dim [error] As Char = buffer.Chars(2) ' ‚±‚±‚ÅŽÀs‚³‚ê‚郁ƒCƒ“EƒAƒvƒŠƒP[ƒVƒ‡ƒ“EƒXƒŒƒbƒh‚Ì—áŠO‚Í ' Application_ThreadException‚Ńnƒ“ƒhƒ‹‚Å‚«‚é Application.Run(New Form1) End Sub ' –¢ˆ——áŠO‚ðƒLƒƒƒbƒ`‚·‚éƒCƒxƒ“ƒgEƒnƒ“ƒhƒ‰iWindowsƒAƒvƒŠƒP[ƒVƒ‡ƒ“—pj Public Shared Sub Application_ThreadException(ByVal sender As Object, ByVal e As ThreadExceptionEventArgs) ShowErrorMessage(e.Exception, "Application_ThreadException‚É‚æ‚é—áŠO’Ê’m‚Å‚·B") End Sub ' –¢ˆ——áŠO‚ðƒLƒƒƒbƒ`‚·‚éƒCƒxƒ“ƒgEƒnƒ“ƒhƒ‰iŽå‚ɃRƒ“ƒ\[ƒ‹EƒAƒvƒŠƒP[ƒVƒ‡ƒ“—pj Public Shared Sub Application_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) Dim ex As Exception = CType(e.ExceptionObject, Exception) If Not ex Is Nothing Then ShowErrorMessage(ex, "Application_UnhandledException‚É‚æ‚é—áŠO’Ê’m‚Å‚·B") End If End Sub ' ƒ†[ƒU[EƒtƒŒƒ“ƒhƒŠ‚ȃ_ƒCƒAƒƒO‚ð•\Ž¦‚·‚郁ƒ\ƒbƒh Public Shared Sub ShowErrorMessage(ByVal ex As Exception, ByVal extraMessage As String) MessageBox.Show(extraMessage & vbLf & "\\\\\\\\" & vbLf & vbLf & _ "ƒGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½BŠJ”­Œ³‚É‚¨’m‚点‚­‚¾‚³‚¢" & vbLf & vbLf & _ "yƒGƒ‰[“à—ez" & vbLf & ex.Message & vbLf & vbLf & _ "yƒXƒ^ƒbƒNƒgƒŒ[ƒXz" & vbLf & ex.StackTrace) End Sub End Class