本文整理汇总了VB.NET中System.Threading.ThreadExceptionEventArgs.Exception属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ThreadExceptionEventArgs.Exception属性的具体用法?VB.NET ThreadExceptionEventArgs.Exception怎么用?VB.NET ThreadExceptionEventArgs.Exception使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Threading.ThreadExceptionEventArgs
的用法示例。
在下文中一共展示了ThreadExceptionEventArgs.Exception属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: CustomExceptionHandler
' 导入命名空间
Imports System.Threading
Imports System.Windows.Forms
' Create a form with a button that, when clicked, throws an exception.
Public Class ErrorForm : Inherits Form
Friend WithEvents button1 As Button
Public Sub New()
' Add the button to the form.
Me.button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
Me.button1.Location = New System.Drawing.Point(100, 43)
Me.button1.Size = New System.Drawing.Size(75, 23)
Me.button1.Text = "Click!"
Me.Controls.Add(Me.button1)
Me.Text = "ThreadException"
Me.ResumeLayout(False)
End Sub
' Throw an exception when the button is clicked.
Private Sub button1_Click(sender As Object, e As System.EventArgs) _
Handles button1.Click
Throw New ArgumentException("The parameter was invalid.")
End Sub
Public Shared Sub Main()
' Add the event handler.
AddHandler Application.ThreadException,
AddressOf CustomExceptionHandler.OnThreadException
' Start the example.
Application.Run(New ErrorForm())
End Sub
End Class
' Create a class to handle the exception event.
Friend Class CustomExceptionHandler
'Handle the exception event.
Public Shared Sub OnThreadException(sender As Object, t As ThreadExceptionEventArgs)
Dim result As DialogResult = ShowThreadExceptionDialog(t.Exception)
' Exit the program when the user clicks Abort.
If result = DialogResult.Abort Then
Application.Exit()
End If
End Sub
' Create and display the error message.
Private Shared Function ShowThreadExceptionDialog(e As Exception) As DialogResult
Dim errorMsg As String = "An error occurred. Please contact the " &
"adminstrator with the following information:" &
vbCrLf & vbCrLf
errorMsg &= "Exception Type: " & e.GetType().Name & vbCrLf & vbCrLf
errorMsg &= e.Message & vbCrLf & vbCrLf
errorMsg &= "Stack Trace: " & vbCrLf & e.StackTrace
Return MessageBox.Show(errorMsg, "Application Error",
MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop)
End Function
End Class