There is one event in the application class for WPF: Dispatcherunhandledexception, which occurs when the application does not handle the exception, thus putting the final door for the application.
1 namespaceChapter1_wpfapplication12 {3 /// <summary>4 ///Interaction logic for App.xaml5 /// </summary>6 Public Partial classapp:application7 {8 protected Override voidOnstartup (StartupEventArgs e)9 {Ten Base. Onstartup (e); One A This. Dispatcherunhandledexception + =app_dispatcherunhandledexception; - } - the voidApp_dispatcherunhandledexception (Objectsender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) - { - Throw Newnotimplementedexception (); - } + } -}
View Code
Obviously, this can be used as a backup method, but it is not possible to rely on it to solve the problem proactively, or to have a good habit of catching anomalies.
WPF Professional Programming Guide-Dispatcherunhandledexception