2022-02-04 16:28:24 +00:00

50 lines
1.1 KiB
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
[source,javascript]
----
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
[source,javascript]
----
function foo() {
try {
return 1; // We expect 1 to be returned
} catch(err) {
return 2; // Or 2 in cases of error
}
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]