Total .NET Analyzer Rule Documentation

 

EmptyTry Rule

Review empty Try statements.

Remarks

Visual Studio .NET structured exception handling uses Try...Catch statements to trap for exceptions in code. The Try block contains the code segment expected to raise an exception. By having no code in a Try statement, you are not specifying the segment of code for exception handling.

For instance, the following code has an empty Try statement:


' VB
Try

Catch e As Exception
Console.WriteLine("An error occurred: '{0}'", e)
End Try

// C#
try
{

}
catch(Exception e)
{
Console.WriteLine("An error occurred: '{0}'", e);
}

In general, empty Try statements do not serve a purpose, and should be removed.

Resolution

Review empty Try statements to determine whether they represent undone work, contain commented code that should be enabled, or do nothing and should be removed.

See Also

Try Statements (VB)
Try Statements (C#)

Total .NET Analyzer On Error Rule