public class EcTest {
public static void main(String[] args) {
System.out.println(testReturn());
}
public static String testReturn() {
try {
int i = 5 / 0;
} catch (Exception e) {
// TODO: handle exception
return e.getMessage();
}
return "hhe";
}
public static void main(String[] args) {
System.out.println(testReturn());
}
public static String testReturn() {
try {
int i = 5 / 0;
} catch (Exception e) {
// TODO: handle exception
return e.getMessage();
}
return "hhe";
}
}
这里返回的是e.getMessage();的内容,如果catch里面有return 就返回
public static String testReturn() {
try {
int i = 5 / 0;
} catch (Exception e) {
e.printStackTrace();
}
return "hhe";
}
如果是这样,即打印堆栈信息又返回‘hhe’;
意思就是如果 catch中没有return 的话 执行完catch之后 会继续往下走。如果catch里面有return 就直接返回。