Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
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 } }
|