Sometimes you need to handle one of several exception types with the same code:
} catch (Exception1 ex) {
LOGGER.log(Level.SEVERE, ex);
throw ex;
} catch (Exception2 ex) {
LOGGER.log(Level.SEVERE, ex);
throw ex;
}
One choice is to find a common supertype of these exceptions and catch just that type. Unfortunately, that can catch more exceptions than you intend. We can change the language to allow more than one exception to be caught in the same catch clause:
} catch (Exception1 | Exception2 ex) {
LOGGER.log(Level.SEVERE, ex);
throw ex;
}