Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Wiki Markup Never use {{return}}, {{break}}, {{continue}}, or {{throw}} statements within a {{finally}} block. When program execution enters a {{try}} block that has a {{finally}} block, the {{finally}} block always executes, regardless of whether the {{try}} block (or any associated {{catch}} blocks) executes to normal completion. Statements that cause the {{finally}} block to complete abruptly also cause the {{try}} block to complete abruptly and consequently suppress any exception thrown from the {{try}} or {{catch}} blocks. According to the _Java Language Specification_, [§14, §14.20.2, Execution of try-catch-finally|http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.20.2] \[ [JLS 2005|AA. References#JLS 05]\]:

If execution of the try block completes abruptly for any other reason R, then the finally block is executed. Then there is a choice:

  • If the finally block completes normally, then the try statement completes abruptly for reason R.
  • If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and reason R is discarded).

...

MITRE CWE

CWE-459. Incomplete cleanup

 

CWE-584. Return inside finally block

Bibliography

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e85775c2-3233-4f1d-96f4-1896c2986a30"><ac:plain-text-body><![CDATA[

[[Bloch 2005AA. References#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="9f43e996-98da-48cb-81f1-c6f268cbcdb7"><ac:plain-text-body><!

[CDATA[ [[Chess 2007AA. References#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="7d0d48cd-dc7f-4a79-af53-b2523a335c49"><ac:plain-text-body><! [CDATA[ [[JLS 2005AA. References#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>

...

      06. Exceptional Behavior (ERR)