Synopsis: | Avoid returning from a finally block |
Language: | Java |
Severity Level: | 1 |
Category: | Basic |
Description: |
Avoid returning from a finally block - this can discard exceptions.public class Bar { public String foo() { try { throw new Exception( "My Exception" ); } catch (Exception e) { throw e; } finally { return "A. O. K."; // Very bad. } } } Justification: According to Java Language Specification: "If execution of the try block completes abruptly for any other reason R, then the finally block is executed, and then there is a choice:
|