WPF专业编程指南

WPF的Application类中有一个事件:DispatcherUnhandledException,在应用程序未对其中的异常加以处理的情况下发生,从而为应用程序把好最后的大门

 1 namespace Chapter1_WpfApplication1
 2 {
 3     /// <summary>
 4     /// Interaction logic for App.xaml
 5     /// </summary>
 6     public partial class App : Application
 7     {
 8         protected override void OnStartup(StartupEventArgs e)
 9         {
10             base.OnStartup(e);
11 
12             this.DispatcherUnhandledException += App_DispatcherUnhandledException;
13         }
14 
15         void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
16         {
17             throw new NotImplementedException();
18         }
19     }
20 }
View Code

很显然,这可以作为后备手段,但是不能依靠它主动解决问题,还是需要良好的捕捉异常的习惯

原文地址:https://www.cnblogs.com/cinlap/p/4468257.html