In java, I often see the process of catching multiple exceptions, logging them in the same way, and throwing them up. I wanted to make it redundant and common, so I looked it up and it seems that I can do it. Reference
catch (IOException ex) {
logger.log(ex);
throw ex;
} catch (SQLException ex) {
logger.log(ex);
throw ex;
}
If you separate them with |
, you can standardize them in the following way.
It seems that it can be used only with java7 or later, so please be careful if you are developing with an older version.
catch (IOException | SQLException ex) {
logger.log(ex);
throw ex;
}
Recommended Posts