...
Code Block | ||
---|---|---|
| ||
class TryFinally {
private static boolean doLogic() {
try {
throw new IllegalStateException();
} finally {
System.out.println("logic done");
}
// Any return statements must go here;
// applicable only when exception is thrown conditionally
}
}
|
...
For instance, the following code does not violate this rule, because the break
statement exits the while
loop, but not the finally
block.
Code Block | ||
---|---|---|
| ||
class TryFinally { private static boolean doLogic() { try { throw new IllegalStateException(); } finally { int c; try { while ((c = input.read()) != -1) { if (c > 128) { break; } } } catch (IOException x) { // forward to handler } System.out.println("logic done"); } // Any return statements must go here; applicable only when exception is thrown conditionally } } |
...
Related Guidelines
CWE-459, ". Incomplete Cleanup" cleanup | |
| CWE-584, "Return Inside Finally Block" . Return inside finally block |
Bibliography
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="42c0c722f46461c2-d91992ea-4cb4406a-bd81b21d-be4f9c26240f273bd635c647"><ac:plain-text-body><![CDATA[ | [[Bloch 2005 | AA. Bibliography#Bloch 05]] | Puzzle 36: . Indecision | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ae87a130824d1ca0-d0fe7729-410e430c-bd008cbb-21b363c95e564ba4cc8f45a1"><ac:plain-text-body><![CDATA[ | [[Chess 2007 | AA. Bibliography#Chess 07]] | 8.2, Managing Exceptions, " The Vanishing Exception " | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="60128b3822412e46-9d925841-48bc49b6-9ad48063-d2793d6307915d4ebede1ac3"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§14.20.2, Execution of try-catch-finally | http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.20.2] | ]]></ac:plain-text-body></ac:structured-macro> |
...