Необработанное исключение

Что лучший способ состоит в том, чтобы обработать необработанное исключение в приложении WPF?

10
задан Lars Truijens 6 June 2011 в 20:58
поделиться

1 ответ

Вы можете использовать DispatcherUnhandledException :

XAML (App.xaml):

<Application x:Class="App.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="wndMain.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException">

Скрытый код (App.xaml.cs / vb:

private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    // Handle error here

    ...

    // Prevent default unhandled exception processing by WPF
    e.Handled = true;
}

Подробнее о читайте здесь . Тем не менее, всегда выполняйте правильную обработку ошибок в первую очередь. Не позволяйте ошибкам просто попадать в этот метод.

13
ответ дан 3 December 2019 в 23:49
поделиться
Другие вопросы по тегам:

Похожие вопросы: