WPF Applications – Handling the Unhandled
- by David Totzke
Instead of just letting your application crash, you can attach a method to the DispatcherUnhandledExceptionEventHandler and one to the AppDomain.Current.UnhandledException. You wire these up in the code behind of your application which by default is App.xaml.cs. You can log these errors or throw up a message Don Box and tell the user what happened. Then you shut down the app gracefully. You shut it down because something bad happened that you weren’t expecting and at this point there is no guarantee as to the state of the stack or memory or anything really. All bets are off. If, on the other hand, the method for the UnhandledException is empty and the method for the DispatcherUnhandledEventHandler ends up in a call to a method called LogError() and the LogError() method is FUCKING EMPTY, and you just swallow the exceptions and keep on running, then, not so much. I spent nearly a day trying to track down a bug that would have been obvious had something been logged or if it just crashed. It’s my own fault I suppose. I knew these were hooked up. I just never suspected that there wouldn’t be any implementation at all. Live and learn. Customs Man at Heathrow: Anything to declare, Sir? Jekyll and Hyde: Man has not evolved an inch from the slime that spawned him. Customs Man at Heathrow: Very Good, Sir. I tend to agree. Dave Just because I can…