The more precise rethrow allows to write code that throws the exception really thrown :
public void foo(String bar) throws FirstException, SecondException {
try{
// Code that may throw both FirstException and SecondException
}
catch (Exception e){
throw e;
}
}
Prior to Java 7 you had to write :
public void foo(String bar) throws Exception {
try{
// Code that may throw both FirstException and SecondException
}
catch (Exception e){
throw e;
}
}
My question: is there a tool that allows to detect imprecise throw in order to replace "Exception" with "FirstException, SecondException"?
So far, I have checked that there is no compiler warning in Eclipse. There is no rule in FindBugs or CodePro.
Try casting the exception before throw, maybe it will do the trick?
BTW, rethrowing the same exception seems rather clumsy thing to me...