DoNotCatchGeneralExceptionTypes – Application.SetUnhandledExceptionMode

Posted: 2009-03-02 in .Net

When we first started using FxCop we were a little confused about how to handle the  “DoNotCatchGeneralExceptionTypes ” Rule, more spefically is it ok to ignore this rule as long as you are at the top of the architecture chain. The typical general try catch log swallow exit approach, to gracefully notify the end user that the game is up and its time to restart.

But enter today!!!! Today while reading through my managers code (weird I know) checking that he hasn’t forgotten the basics of programming I was reminded about why being a smart ass can sometimes backfire, well sometimes 😀

Reviewing program.cs at the very first line I found a line I didn’t understand:


static void Main(string[] args)
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
//Etc etc….
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine(“An unhandied application error has occurred and the application will be closed.”);
//Etc etc….


Basically what my manager had just shown me was away to get rid of the general high level ctach swallow kill try catch block… Fanatastic
Not only this but if you use implement different types of UnhandledExceptionMode you can even extend this down into app.settings… Fanatastic

.Net you have done it to me again.



Update: 20090304 Choco

Found these links that are quiet informative



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s