I think the method1 and the method2 is the same.
Why the compiler complains "missing return statement" in the method2?
Thanks.
public class ExceptionHandlingTest {
public static void main(String[] args) throws Exception {
System.out.println(method1());
}
public static String method1() throws Exception{
try{
return "method1";
}catch(Exception e){
throw new Exception();
}finally{
}
}
public static String method2() throws Exception{
try{
return "method2";
}catch(Exception e){
method3();
}finally{
}
}
public static void method3() throws Exception{
throw new Exception();
}
}
Why the compiler complains "missing return statement" in the method2?
Thanks.
public class ExceptionHandlingTest {
public static void main(String[] args) throws Exception {
System.out.println(method1());
}
public static String method1() throws Exception{
try{
return "method1";
}catch(Exception e){
throw new Exception();
}finally{
}
}
public static String method2() throws Exception{
try{
return "method2";
}catch(Exception e){
method3();
}finally{
}
}
public static void method3() throws Exception{
throw new Exception();
}
}