Avoid empty finally blocks (C#, VB.NET) | CAST Appmarq

Avoid empty finally blocks (C#, VB.NET)


Rule Definition
Finally blocks must be used to execute the code that is needed after either the try and/or the catch block have been executed. It is usually the place to code the release of resources used in the try block. Thus an empty finally block is most probably the sign of potential "resource leaks" that will jeopardize the application's stability.

Violation Code Sample
try { ... }
catch ( MyException e)
{ ,,, }
finally
{
  // DO NOTHING <= VIOLATION
}
Fixed Code Sample
try { ,,, }
catch ( MyException e)
{ ,,, }
finally
{
  DoSomething();
}

Related Technologies

Health Factor

  Security


Technical Criterion
Programming Practices - Error and Exception Handling

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

99.84%

Total Violations
747
Total Opportunities
472,685
Average Violations / App.
9.96
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Insurance

96.55%

Financial Services

99.94%

IT & Business Consulting

99.90%