Module Module1
<STAThread()> _
Sub main()
AddHandler Application.ThreadException, AddressOf application_threadexception
Application.Run(new form1())
End Sub
Sub application_threadexception(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
Try
Dim msg As String = String.Format("An Error has occurred:{0}{0}{1}{0}{0}{2}" _
, ControlChars.Cr, e.Exception.Message, e.Exception.StackTrace)
Dim result As DialogResult = MessageBox.Show(msg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error)
If result = DialogResult.Abort Then
Application.Exit()
End If
Catch '如果不能正常关闭(这种情况可能是exception对象不可用的缘故)
Try
MessageBox.Show("The application will be terminated ", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Application.Exit()
End Try
End Try
End Sub