Avatar of ScottMacMaster
ScottMacMaster
 asked on

Top Level Exception Handling

I'm using the code analyser in Visual Studio 2010 to try to improve my code.  One thing it's complaining about is that I'm catching exceptions of type Exception.  It says I shouldn't do that because it can hide problems from the user of my library and can complicate debugging.  However, I'm not writing a library I'm writing a web app.

I typically have a try/catch block around all the code in each event handler so I can detect an error and display an error message next to whatever the user clicked.  Also, I log the caught exception.  Is this the proper way to do exception handling in web apps?  Or should I review my code to see which exceptions can be thrown (SqlException, IndexOutOfRangeException, ArgumentNullException would probably be the most common) and catch those and let general exceptions go?  I really don't want to do that since I'm using AJAX.  An uncaught exception would result in no content update and that little javascript error icon in the corner of the browser.  Maybe I could catch the error using the Page.Error event handler and display a generic error message somewhere on the web page.

Alternatively, is there a way to set a flag or something to tell the code analyzer that this isn't a library and that this top level code and to not show this error instead of clicking suppress error for each one?

Well, any advise would be helpful/


Thanks,
ASP.NET.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
existenz2

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
existenz2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes