Eating Exceptions… eeehhhh!

Following are few points you need to take care when you decide to eat an exception. These are very much specific to C# language.

a. Limit the code block. Attempt to wrap one or two statements within try.

b. If an exception is eaten, log details to some logging mechanism. In short never write empty catch catch(Exception) {}.

c. Never eat exception that indicates some bad behavior of code execution like - ArgumentNullException,

NullReferenceException,

ArgumentNullException,

InvalidCastException,

InvalidOperationException,

AccessViolationException, etc;

d. There is a big difference between throw and throw exeception statements. This is in terms of resetting stack trace which the later does. If you are writing a framework or want to hide your internal implementation use throw exception, otherwise use throw only.

- Ankit