JDK-4988583 : AutomaticException chaining for exception in try and exception thrown in finally
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.4.2
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-04
  • Updated: 2015-02-18
  • Resolved: 2011-07-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 rcFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: jl125535			Date: 02/04/2004


A DESCRIPTION OF THE REQUEST :
Currently, if an exception, A, occurs withing a try block, and then an exception B occurs in a finally block, then exception A is completely lost. Programmers can use manual exception chaining in situations where an exception may be thrown in a finally block. However, this can make the code very messy.

JUSTIFICATION :
  From a debugging standpoint it would be useful to see the information from both exceptions without the need to add extra lines of code to do exception chaining.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would Java to automatically using exception chaining behind the scenes in a situation where an exception occurs in a try block and a finally block.

ACTUAL -

So in the situation where a try block throws Exception A, and a finally block throws Exception B,  if exception A and B occur then exception B is thrown with Exception A as its init cause.

CUSTOMER SUBMITTED WORKAROUND :
Use manual exception chaining.
(Incident Review ID: 237013) 
======================================================================

Comments
EVALUATION Suppressed exceptions introduced in Java SE 7 for the try-with-resources statement seem to address this need.
22-07-2011

EVALUATION The true cause of an exception thrown in finally may be unrelated to any of the exceptions thrown in a try block (or catch blocks, for that matter). Having said that, I quite like this CR. It is more sensible than many exception proposals. However, it cannot be done yet. Chained exceptions were only introduced in 1.4. For bytecode that might run on 1.3, we cannot use the Throwable(Throwable) constructor or calls Throwable.initCause. And there are still a lot of 1.3 JVMs out there. (For information: implementing this CR would mean adding an entry for the finally block's instructions to the exception table. This would mean changing JVMS 4.9.6 and 7.13, as well as respecifying JLS 11.3 and 14.20.)
10-11-2006

EVALUATION This RFE is requesting a specification change.
08-11-2006