未处理的异常 [英] Unhandled exception

查看:191
本文介绍了未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

您可以使用 DispatcherUnhandledException



XAML(App.xaml):

 <应用程序x:Class =App.App
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns: x =http://schemas.microsoft.com/winfx/2006/xaml
StartupUri =wndMain.xamlDispatcherUnhandledException =Application_DispatcherUnhandledException>

代码背后(App.xaml.cs / vb:

  private void Application_DispatcherUnhandledException(object sender,System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
//处理错误在这里

...

//防止WPF的默认未处理异常处理
e.Handled = true;
}

阅读更多在这里。始终做到正确的错误处理量首先,不要只是让错误滑入这种方法。


What is the best way to handle an unhandled exception in a WPF application?

解决方案

You can use 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">

Code Behind (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;
}

Read up more here. Always do the correct amount of error handling in the first place though. Don't just let errors slip into this method.

这篇关于未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆