全局程序异常处理

wpf程序

在App.xaml中增加如下代码

 1 DispatcherUnhandledException="Application_DispatcherUnhandledException" 

 

完成代码如下:

<Application x:Class="WpfApp1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp1"
             StartupUri="MainWindow.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException">
    <Application.Resources>
         
    </Application.Resources>
</Application>

在App.xaml.cs中增加如下代码

1     public partial class App : Application
2     {
3         private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
4         {
5             //全局程序异常处理
6             MessageBox.Show("提示程序中出现了严重错误,请联系软件开发商"+e.Exception.Message);
7             e.Handled = true;
8         }
9     }

 

posted @ 2017-12-02 10:33  pop1234ggg  阅读(195)  评论(0编辑  收藏  举报