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 is working fine, but when I change return type of testMethod()
to void and changing the line return 4;
to System.out.println("some print msg");
is causing compilation problem.
Can anybody please give solution for why it is giving compilation error?