我真的很想使用 Java-1.7 的特性。此功能之一是“多捕获”。目前我有以下代码
try {
int Id = Integer.parseInt(idstr);
TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id));
updateTotalCount(tempTypeInfo);
} catch (NumberFormatException numExcp) {
numExcp.printStackTrace();
} catch (Exception exception) {
exception.printStackTrace();
}
我想从上面的代码中删除两个 catch 块,而是使用如下的单个 catch:
try {
int Id = Integer.parseInt(idstr);
TypeInfo tempTypeInfo = getTypeInfo(String.valueOf(Id));
updateTotalCount(tempTypeInfo);
} catch (Exception | NumberFormatException ex) { // --> compile time error
ex.printStackTrace();
}
但是上面的代码给出了编译时错误:
“NumberFormatException”已被替代异常捕获。
我理解了上面的编译时错误,但是我的第一个代码块的替换是什么。