ThreadExceptionEventArgs 클래스

정의

ThreadException 이벤트에 대한 데이터를 제공합니다.Provides data for the ThreadException event.

public ref class ThreadExceptionEventArgs : EventArgs
public class ThreadExceptionEventArgs : EventArgs
type ThreadExceptionEventArgs = class
    inherit EventArgs
Public Class ThreadExceptionEventArgs
Inherits EventArgs
상속
ThreadExceptionEventArgs
파생

예제

다음 예제에서는 시킬 수 있습니다는 ThreadException 를 클릭 하 여 이벤트 button1 양식의 합니다.The following example allows you to raise a ThreadException event by clicking button1 on a form. 이 예제에서는 두 개의 클래스를 만듭니다.The example creates two classes. ErrorHandler 클래스 형식 및 이벤트를 발생 시키는 단추를 만듭니다.The ErrorHandler class creates the form and the button that raises the event. CustomExceptionHandler 클래스 예외를 처리 하는 메서드를 제공 합니다.The CustomExceptionHandler class provides the methods to handle the exception.

MainErrorHandler 클래스 코드는 예외 처리, 클래스의 인스턴스의 새 인스턴스를 만듭니다는 CustomExceptionHandler합니다.In Main in the ErrorHandler class, the code creates a new instance of the exception handling class, that is, an instance of the CustomExceptionHandler. 이벤트를 인스턴스에 추가 되는 다음 하 고 애플리케이션이 실행 됩니다.Then the instance is added to the event, and the application is run.

OnThreadException 에서 메서드를 CustomExceptionHandler 클래스를 사용 하 여를 try...catch...finally 예외 처리 문을 합니다.In the OnThreadException method in the CustomExceptionHandler class, the example uses a try...catch...finally statement to process the exception. ShowThreadExceptionDialog 메서드를 표시할 메시지를 만듭니다. 메시지 상자에 표시 합니다.The ShowThreadExceptionDialog method creates the message to display, and displays it in a message box.

using System;
using System.Threading;
using System.Windows.Forms;

// Create a form with a button that, when clicked, throws an exception.
 public class ErrorForm : System.Windows.Forms.Form
 {
    internal Button button1;

    public ErrorForm() : base()
    {
       // Add the button to the form.
       this.button1 = new System.Windows.Forms.Button();
       this.SuspendLayout();
       this.button1.Location = new System.Drawing.Point(100, 43);
       this.button1.Size = new System.Drawing.Size(75, 23);
       this.button1.Text = "Click!";
       this.Controls.Add(this.button1);
       this.button1.Click += new EventHandler(this.button1_Click);

       this.Text = "ThreadException";
       this.ResumeLayout(false);
    }

    // Throw an exception when the button is clicked.
    private void button1_Click(object sender, System.EventArgs e)
    {
       throw new ArgumentException("The parameter was invalid");
    }
 
    public static void Main()
    {
       // Add the event handler.
       Application.ThreadException += new ThreadExceptionEventHandler(CustomExceptionHandler.OnThreadException);

       // Start the example.
       Application.Run(new ErrorForm());
    }
 }
 
 // Create a class to handle the exception event.
 internal class CustomExceptionHandler
 {
     // Handle the exception event
    public static void OnThreadException(object sender, ThreadExceptionEventArgs t)
    {
       DialogResult result = ShowThreadExceptionDialog(t.Exception);

       // Exit the program when the user clicks Abort.
       if (result == DialogResult.Abort) 
          Application.Exit();
    }
 
    // Create and display the error message.
    private static DialogResult ShowThreadExceptionDialog(Exception e)
    {
       string errorMsg = "An error occurred.  Please contact the adminstrator " +
            "with the following information:\n\n";
       errorMsg += String.Format("Exception Type: {0}\n\n", e.GetType().Name);
       errorMsg += "\n\nStack Trace:\n" + e.StackTrace;
       return MessageBox.Show(errorMsg, "Application Error", 
            MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
    }
 }
 
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

설명

ThreadExceptionEventArgs 처리 되지 않은 예외가 발생 하면 스레드에 의해 생성 됩니다.A ThreadExceptionEventArgs is created by a thread when an unhandled exception occurs. ThreadExceptionEventArgs 포함 된 Exception 발생 한 합니다.ThreadExceptionEventArgs contains the Exception that occurred.

생성자

ThreadExceptionEventArgs(Exception)

ThreadExceptionEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the ThreadExceptionEventArgs class.

속성

Exception

발생한 Exception을 가져옵니다.Gets the Exception that occurred.

메서드

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(다음에서 상속됨 Object)

적용 대상

추가 정보