Do NOT eat exceptions (C# .NET)
Proper exception handling is part of writing good code. Here’s a quick tip – if you don’t want to handle an exception, fine, just leave it., don’t put any try/catch and just let the exception propogate up to it’s caller.
If you are not sure why you are using try/catch, maybe you shouldn’t be using it. It should not be used to control execution flow of the program, rather it should be used for ‘exceptional’ circumstances.
However, if you decide you don’t want to handle the exceptions and rather you do the following, that is very bad:
try
{
//do something that will throw an exception, like try to execute an invalid SQL statement
}
catch
{
//sweep the dirt under the rug ;
}
Consequences of swallowing exceptions blindly - Your boss will not see any exceptions or code crashes, but it might come back to bite you in the butt when the code doesn’t do what it was supposed to! You have no idea what you just swallowed, except it didn’t taste too good and looked kinda funny.
Additional Sources
Here’s an article by Steven Swafford discussing eating exceptions (among other things) – http://aspadvice.com/blogs/sswafford/archive/2007/05/10/Skills-versus-Passion_2C00_-are-they-the-same_3F00_.aspx
As a follow up, read Use TryParse Instead of Try/Catch
Related Reading:
Other Interesting Posts
-
Articles
- January 2011
- April 2010
- March 2010
- February 2010
- January 2010
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- February 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
-
Meta







