Home > Code Analysis > Code Issues – Control cannot leave the body of a finally clause

Code Issues – Control cannot leave the body of a finally clause

October 18th, 2012

Cause:

Returns are forbidden in finally clauses by the compiler. A compiler error will occur in case of a return statement inside a finally block, and refuse to let you write such potentially ambiguous and confusing code. The purpose of a finally statement is to ensure that the necessary cleanup of objects happens immediately and always. In other words, it is designed for releasing all locks and resources and cannot leave the block until finishing the cleanup task.

Sample:

CodeRush Control Cannot Leave The Body Of A Finally Clause Sample

How to Fix:

  • Remove the return statement from a finally block:

CodeRush Control Cannot Leave The Body Of A Finally Clause Fix

 

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Oct/18/2012
ID: C201

Similar Posts: