WPF Applications – Handling the Unhandled
Posted
by David Totzke
on Geeks with Blogs
See other posts from Geeks with Blogs
or by David Totzke
Published on Thu, 22 Apr 2010 18:27:43 GMT
Indexed on
2010/04/22
18:43 UTC
Read the original article
Hit count: 407
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…
© Geeks with Blogs or respective owner