项目中出现如下报错,导致无法编译。
jdk7官网给出的解释是:
The exception types in multiple catch block must be disjoint, one exception cannot be a subclass of another exception.
这样写的话,IOException是Exception的子类,所以编译的时候就会报错。
正确的写法是:
catch(IOException | SQLException ex){
logger.error(ex);
…
} catch(Exception e){
logger.error(e);
…
}