Monday, August 6, 2007

Don't propagate exceptions to the user

Catch every exception in your application.
If you must, show the user some kind of an error dialog, but don't force him/her to watch the awful .Net exception dialog.
I have seen to many application with various try...catch blocks, but with nothing done to capture handled exceptions, resulting in those exceptions crashing the application, being displayed to the user, and some times without being written to any log file (making them useless).
It's strange, but some people are still not aware of the Application.ThreadException and AppDomain.UnhandledException events, used to capture unhandled exceptions. You can also use the UnhandledExceptionMode enumeration to specify which event (of the two above) should receive exceptions.
You can also surround the Application.Run call with a try..catch block.

No comments: