public class ExceptionTest {
public static void main(String[] args) {
ExceptionTest et = new ExceptionTest();
try {
et.testMethod();
} catch (Exception e) {
e.printStackTrace();
}
}
public int testMethod() {
try {
throw new Exception();
}finally {
return 4;
}
}
The above code works fine, but when I change the return type testMethod()to void and change the string return 4;to System.out.println("some print msg");, there is a compilation problem.
Can someone please give a decision why it gives a compilation error?
source
share