Pregunta

¿Cuál es la mejor manera de manejar una excepción no controlada en una aplicación WPF?

¿Fue útil?

Solución

Puede utilizar 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">

Código Atrás (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;
}

más aquí . Siempre hacer la cantidad correcta de tratamiento de errores en el primer lugar sin embargo. No se limite a dejar que los errores se deslizan en este método.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top