public class TryTest {
public static void main(String[] args) {
String result = get();
System.out.println(result);
}
public static String get(){
int value = 0;
try {
System.out.println("try……");
//等式1/0 :分母为0 的明显错误 ——制造错误(用于抛异常)
int result = 1 / value;
return "111";
} catch (Exception e) {
System.out.println("catch……");
return "444";
} finally {
System.out.println("finally……");
return "333";
}
return "222";
}
执行结果:
try……
catch……
finally……
333
public class TryTest {
public static void main(String[] args) {
// 调用 测试方法
String result = get();
// 打印 测试方法返回的结果
System.out.println(result);
}
public static String get(){
try {
System.out.println("try……");
return "111";
} catch (Exception e) {
System.out.println("catch……");
} finally {
System.out.println("finally……");
}
return "222";
}
}
执行结果:
try……
finally……
111
trycatch执行顺序.png
网友评论