JDK-6943289 : Project Coin: Improved Exception Handling for Java (aka 'multicatch')
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: unknown
  • Submitted: 2010-04-13
  • Updated: 2022-07-08
  • Resolved: 2011-03-08
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 b94Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
This proposal is structured into two different parts:

*) Catching multiple exception types: A single catch clause can now catch
   more than one exception types, enabling a series of otherwise identical
   catch clauses to be written as a single catch clause.

*) Improved checking for rethrown exceptions:  Previously, rethrowing an
   exception was treated as throwing the type of the catch parameter.  Now,
   when a catch parameter is declared final, rethrowing the exception is known
   statically to throw only those checked exception types that were thrown in
   the try block, are a subtype of the catch parameter type, and not caught in
   preceding catch clauses.

EXAMPLE (multicatch):

before:

try {
    doWork(file);
} catch (IOException ex) {
    logger.log(ex);
} catch (SQLException ex) {
    logger.log(ex);
}

after:

try {
    doWork(file);
} catch (final IOException|SQLException ex) {
    logger.log(ex);
}

EXAMPLE (rethrow)

before

void m() throws IOException, SQLException {
try {
   doWork(file);
} catch (IOException) {
    logger.log(ex);
} catch (SQLException ex) {
    logger.log(ex);
    throw ex; //rethrows IOException,SQLException
}
}

after:

void m() throws SQLException {
try {
   doWork(file);
} catch (IOException) {
    logger.log(ex);
} catch (final SQLException ex) {
    logger.log(ex);
    throw ex; //rethrows SQLException
}
}

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/a6f2911a7c55
12-05-2010

EVALUATION A fine feature.
04-05-2010