Fork me on GitHub
TypeName EmptyCatchBlockAnalyzer
Check Id CC0004
Category Design
Severity Warning

Cause

An empty catch block suppress all errors and shouldn’t be used.
If the error is expected consider logging it or changing the control flow such that it is explicit.

Example

try
{
    // do something
}
catch
{
}

Code fix

You will have the choice to remove the Try-Catch block altogether, with the option to place a TODO message with a link to MSDN on how to use try-catch statements. You will also have the choice to add an Exception class and throw it:

try
{
    // do something
}
catch (Exception ex)
{
    throw;
}

Code fix

Related rules

  • CC0003 - Catch statement should include Exception class

See also

TBD