Java 7之前的版本:
1
2
3
4
5
6
7
8
9
10
|
catch (IOException ex) { logger.error(ex); throw new MyException(ex.getMessage()); catch (SQLException ex) { logger.error(ex); throw new MyException(ex.getMessage()); } catch (Exception ex) { logger.error(ex); throw new MyException(ex.getMessage()); } |
1
|
在Java 7 中,我们可以用一个 catch 块捕获所有这些异常: |
1
2
3
4
|
catch (IOException | SQLException | Exception ex){ logger.error(ex); throw new MyException(ex.getMessage()); } |
1
|
|