Only use Catch(SomeException ex) if you are willing to handle SomeException. Exceptions which you are not willing to handle are counted as unexpected. Use unit tests to exercise your code and find the expected exceptions.
The following example is wrong because you're not doing anything with the exception
try
{
// Some code that throws a exception
}
catch(Exception ex) // Only handle this type of exception in the User interface.
{
throw; // Incorrect, throwing exception for no reason
}
This is better:
try
{
// Some code that throws a exception
}
catch(System.Data.UpdateException ex)
{
LogException(ex);
string message = DecipherException(ex);
throw new MyException(message, ex); // Incorrect
}
And follow up with (in the user interface)
try
{
// Code that throws a exception
}
catch (MyException myEx)
{
// Use a nice dialog which shows the user how to fix the error
}
catch (Exception ex)
{
// Unhandled scenario - usually fatal because you didn't expect it to happen.
}