更精确的重新抛出允许编写抛出真正抛出的异常的代码:
public void foo(String bar) throws FirstException, SecondException {
try{
// Code that may throw both FirstException and SecondException
}
catch (Exception e){
throw e;
}
}
在 Java 7 之前,您必须编写:
public void foo(String bar) throws Exception {
try{
// Code that may throw both FirstException and SecondException
}
catch (Exception e){
throw e;
}
}
我的问题:是否有一种工具可以检测不精确的投掷以将“ Exception
”替换为“ FirstException, SecondException
”?
到目前为止,我已经检查了 Eclipse 中没有编译器警告。FindBugs 或 CodePro 中没有规则。