まちがい
こんなフォームを作ってエラーを投げます。
エントリポイントはこれ。Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Throw New IO.FileNotFoundException("ファイルないねん") End Sub End Class
Public Class Program <STAThread()> _ Public Shared Function Main(ByVal CmdArgs() As String) As Integer Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Try Application.Run(New Form1()) Catch ex As Exception MessageBox.Show("エラーだよ。" & ex.Message & "なんだって。おわるね。") End Try End Function End Class
これ,きゃっちされないんですよ…。
しゅうせい・そのいち
ここを参考に おまじない。
ん,うまくいくみたいだね。Public Class Program <STAThread()> _ Public Shared Function Main(ByVal CmdArgs() As String) As Integer Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) AddHandler Application.ThreadException, AddressOf Application_ThreadException AddHandler Threading.Thread.GetDomain().UnhandledException, AddressOf Application_UnhandledException Application.Run(New Form1()) End Function Public Shared Sub Application_ThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs) ShowErrorMessage(e.Exception, "Application.ThreadException をきゃっち!") End Sub 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 をきゃっち!") End If End Sub Public Shared Sub ShowErrorMessage(ByVal ex As Exception, ByVal extraMessage As String) MessageBox.Show("エラーだよ。おわるね。" & vbCr & extraMessage & vbCr & ex.Message) End Sub End Class
ここからがほんだい
これは……?
Public Class Program <STAThread()> _ Public Shared Function Main(ByVal CmdArgs() As String) As Integer Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) AddHandler Application.ThreadException, AddressOf Application_ThreadException AddHandler Threading.Thread.GetDomain().UnhandledException, AddressOf Application_UnhandledException Application.Run(New Form1()) Application.Run(New Form2()) End Function : : End Class
Form2
のほうがきゃっちできないんだよ……。かいけつ
よくわかんないけどこうするといいみたい。
…そもそも,Public Class Program <STAThread()> _ Public Shared Function Main(ByVal CmdArgs() As String) As Integer Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) AddHandler Application.ThreadException, AddressOf Application_ThreadException AddHandler Threading.Thread.GetDomain().UnhandledException, AddressOf Application_UnhandledException Application.Run(New Form1()) AddHandler Application.ThreadException, AddressOf Application_ThreadException AddHandler Threading.Thread.GetDomain().UnhandledException, AddressOf Application_UnhandledException Application.Run(New Form2()) End Function : : End Class
Application.Run()
がふたつあるのがまちがいらしいんだけど。
0 件のコメント:
コメントを投稿