多catch块的代码优化

通常情况下编码的时候,针对不同的异常类型,会使用多个catch块包住,来对各自的异常做处理,如下所示:

try{
...
}catch(***Exception e){
    e.printStackTrace();
}catch(***Exception e){
    e.printStackTrace();
}

通常会提示如下警告:

Reports identical catch sections in try blocks under JDK 7. A quickfix is available to collapse the sections into a multi-catch section.
This inspection only reports if the project or module is configured to use a language level of 7.0 or higher.

我这个人有强迫症,看到警告就想去掉,所以就了解了一下这个警告的意思,大致就是说,jdk7之后把catch块代码折叠起来更高效。

try{
...
}catch(***Exception | ***Exception e){
    e.printStackTrace();
}

通常情况下编码的时候,针对不同的异常类型,会使用多个catch块包住,来对各自的异常做处理,如下所示:

try{
...
}catch(***Exception e){
    e.printStackTrace();
}catch(***Exception e){
    e.printStackTrace();
}

通常会提示如下警告:

Reports identical catch sections in try blocks under JDK 7. A quickfix is available to collapse the sections into a multi-catch section.
This inspection only reports if the project or module is configured to use a language level of 7.0 or higher.

我这个人有强迫症,看到警告就想去掉,所以就了解了一下这个警告的意思,大致就是说,jdk7之后把catch块代码折叠起来更高效。

try{
...
}catch(***Exception | ***Exception e){
    e.printStackTrace();
}

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-10-04
  • 2021-12-27
猜你喜欢
  • 2022-01-17
  • 2022-12-23
  • 2021-08-25
  • 2021-08-02
  • 2021-04-30
  • 2021-07-09
  • 2021-08-03
相关资源
相似解决方案