Coding Practice: Exception Handling

Coding Practice: When should I ignore exceptions?
There is never an acceptable time to catch an exception and ignore it.  If you catch an exception, at the very least you should log the exception.  If an exception gets thrown frequently, then this is an indication that something is fundamentally wrong with your code and you should fix it at the root.

Quote:
“The worst thing you can do is catch (Exception) and put an empty code block on it. Never do this.”
–            Daniel Turini

Application:
You should never have code written in this way:

try
{
   int val = GenericLibrary.ConvertToInt(userInput);
   return val;
}
catch (Exception)
{
   //this always throws an exception and I don’t know why
}

References:
http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET

About Chris VanHoose

Principal Software Architect at CT Lien Solutions
This entry was posted in Software Architecture and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.