I have two snippet of code :
class PreciseRethrow {
public static void main(String[] str) {
try {
foo();
} catch (NumberFormatException ife)
Here ,You are throwing new Exception() from catch block but you have mentioned your method foo() can throw only NumberFormatException() which is lower in hierarchy
static private void foo() throws NumberFormatException {
try {
int i = Integer.parseInt("ten");
} catch (Exception e) {
throw new Exception();
}
}