|
Hi Scott, in our application we are using database constraints to check the validity of the data. With the current code this is not possible at all. If there is a second exception in the catch or finally block then this one will be thrown. The original exception from the try block that might be useful for the user is lost. Therefore the exception in the try block should always be returned (imo). Either directly or as a cause of another exception.
If we could use Java 7 then the exception from the try block could be thrown and any exception from within catch or finally could be added to its supressed exceptions.
Since Java 7 is not an option at the moment, the following could be done: If there is an exception in the try block 1. ... only then throw this one. 2. ... and a subsequent exception in the finally block then throw the exception from the finally block and add the one from the try block as its cause. 3. ... and a subsequent exception in the catch block and no exception in the finally block then throw the one from the catch block with the one from the try block as its cause. 4. ... and a subsequent exception in the catch block and in the finally block then log the one from the finally block and throw the one from the catch block with the one from the try block as its cause.
I've already added pull request #647 some weeks ago for this. I could adapt it to reflect the changes mentioned in this comment.
|