10

WPF アプリケーションで未処理の例外を処理する最良の方法は何ですか?

4

1 に答える 1

13

使用できます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;
}

詳しくはこちらをご覧ください。ただし、最初は常に正しい量のエラー処理を行ってください。このメソッドにエラーが入り込まないようにしてください。

于 2010-02-12T12:55:41.503 に答える