2020-12-23 14:59:06 +01:00

32 lines
814 B
Plaintext

Using ``return``, ``break``, ``throw``, and ``continue`` from a ``finally`` block overwrites similar statements from the suspended ``try`` and ``catch`` blocks.
This rule raises an issue when a jump statement (``break``, ``continue``, ``return`` and ``throw``) would force control flow to leave a ``finally`` block.
== Noncompliant Code Example
----
function foo() {
try {
return 1; // We expect 1 to be returned
} catch(err) {
return 2; // Or 2 in cases of error
} finally {
return 3; // Noncompliant: 3 is returned before 1, or 2, which we did not expect
}
}
----
== Compliant Solution
----
function foo() {
try {
return 1; // We expect 1 to be returned
} catch(err) {
return 2; // Or 2 in cases of error
}
}
----
include::../see.adoc[]