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

Other Interesting Posts

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*


+ 3 = 10

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>