【发布时间】:2017-06-14 14:18:33
【问题描述】:
关于 java-7 功能“精确重新抛出”和final Exception ex 有很多问题,我找不到我的问题的明确答案。
“精确重新抛出”和 final Exception 之间的关系是什么?
public static void main(String args[]) throws OpenException, CloseException {
boolean flag = true;
try {
if (flag){
throw new OpenException();
}
else {
throw new CloseException();
}
}
catch (final Exception e) {
System.out.println(e.getMessage());
throw e;
}
}
如果我想使用“精确重新抛出”,是否必须使用 final 关键字?
catch (final Exception e) {
System.out.println(e.getMessage());
throw e;
}
如果不是强制性的,我可以将 ex 引用重新分配给新的异常吗?
catch (Exception e) {
System.out.println(e.getMessage());
e=new AnotherException();
throw e;
}
【问题讨论】:
标签: java exception-handling java-7