Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Implemented
-
Trunk
-
None
-
None
Description
In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication and lessen the temptation to catch an overly broad exception.
For more details: https://docs.oracle.com/javase/8/docs/technotes/guides/language/catch-multiple.html
Example:
catch (IOException ex) { logger.log(ex); throw ex; } catch (SQLException ex) { logger.log(ex); throw ex; }
Can be written as, which is valid in Java SE 7 and later, eliminates the duplicated code:
catch (IOException | SQLException ex) { logger.log(ex); throw ex; }