finally block should not execute return or throw after try-catch block already executes return or throw

  • BAD_FINALLY_CONTROL_FLOW
  • Error
  • Medium
  • No tags

This rule applies when finally block executes return or throw after try-catch already executes return or throw.

If the finally block executes return or throw a value, it overwrites the previous result of try-catch block.

Noncompliant Code Example

View with compliant examples side by side
try {
    return foo();
} catch (e) {
    return bar();
} finally {
    return finalFunc(); // BAD_FINALLY_CONTROL_FLOW alarm because this will overwirte try-catch return value.
}

Compliant Code Example

View with noncompliant examples side by side
try {
    return foo();
} catch (e) {
    return bar();
} finally {
    finalFunc();
}

Version

This rule was introduced in DeepScan 1.8.0-beta.

See

Was this documentation helpful?