언어

Application.DispatcherUnhandledException 이벤트

정의

애플리케이션에서 예외가 throw되었지만 처리되지 않을 때 발생합니다.

public:
 event System::Windows::Threading::DispatcherUnhandledExceptionEventHandler ^ DispatcherUnhandledException;
public event System.Windows.Threading.DispatcherUnhandledExceptionEventHandler DispatcherUnhandledException;
member this.DispatcherUnhandledException : System.Windows.Threading.DispatcherUnhandledExceptionEventHandler 
Public Custom Event DispatcherUnhandledException As DispatcherUnhandledExceptionEventHandler 

이벤트 유형

예제

다음 예제에서는 이벤트를 처리 하 여 처리 되지 않은 예외를 처리 하는 방법을 보여 줍니다 DispatcherUnhandledException .

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

namespace SDKSample
{
    public partial class App : Application
    {
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            // Process unhandled exception

            // Prevent default unhandled exception processing
            e.Handled = true;
        }
    }
}
Imports System.Windows
Imports System.Windows.Threading

Namespace SDKSample
    Partial Public Class App
        Inherits Application
        Private Sub App_DispatcherUnhandledException(ByVal sender As Object, ByVal e As DispatcherUnhandledExceptionEventArgs)
            ' Process unhandled exception

            ' Prevent default unhandled exception processing
            e.Handled = True
        End Sub
    End Class
End Namespace

설명

기본적으로 Windows Presentation Foundation은 처리되지 않은 예외를 catch하고, 대화 상자에서 예외를 사용자에게 알리고(예외를 보고할 수 있음) 애플리케이션을 자동으로 종료합니다.

그러나 애플리케이션이 중앙 집중식 위치에서 사용자 지정 처리되지 않은 예외 처리를 수행해야 하는 경우 처리 DispatcherUnhandledException해야 합니다.

DispatcherUnhandledException 은 주 UI 스레드에서 실행되는 코드에 의해 처리되지 않는 각 예외에 의해 발생 Application 합니다.

백그라운드 UI 스레드(자체 Dispatcher스레드) 또는 백그라운드 작업자 스레드(스레드가 없는 Dispatcher스레드)에서 예외가 처리되지 않는 경우 예외는 주 UI 스레드로 전달되지 않습니다. 따라서 발생하지 DispatcherUnhandledException 않습니다. 이러한 경우 다음을 수행하려면 코드를 작성해야 합니다.

  1. 백그라운드 스레드에서 예외를 처리합니다.

  2. 이러한 예외를 주 UI 스레드로 디스패치합니다.

  3. 발생을 허용 DispatcherUnhandledException 하도록 처리하지 않고 주 UI 스레드에서 다시 throw합니다.

자세한 내용은 스레딩 모델 개요를 참조하세요.

DispatcherUnhandledException 이벤트 처리기는 다음을 DispatcherUnhandledExceptionEventArgs 포함하여 예외와 관련된 컨텍스트 정보를 포함하는 인수를 전달합니다.

이 정보를 사용하여 예외를 복구할 수 있는지 여부를 확인할 수 있습니다. 예를 들어 복구할 수 FileNotFoundException없는 예외는 복구할 수 없는 예외일 StackOverflowException수 있습니다.

처리되지 않은 예외를 처리하고 WPF에서 DispatcherUnhandledException처리를 계속하지 않으려면 속성을 Handled로 설정 true 해야 합니다.

발생하는 다른 이벤트 Application 와 DispatcherUnhandledException 달리 일치하는 보호된 가상 구현(OnDispatcherUnhandledException)이 없습니다. 따라서 파생 Application 되는 클래스는 처리되지 않은 예외를 처리하기 위해 항상 이벤트 처리기를 DispatcherUnhandledException 등록해야 합니다.

적용 대상