public static void enterTryMethod() {
System.out.println("enter after try field");
}
public static void enterExceptionMethod() {
System.out.println("enter catch field");
}
public static void enterFinallyMethod() {
System.out.println("enter finally method");
}
public static int catchTest() {
int res = 0;
try {
res = 10 / 0; // 抛出Exception,后续处理被拒绝
enterTryMethod();
return res; // Exception已经抛出,没有获得被执行的机会
} catch (Exception e) {
enterExceptionMethod();
return 1; // Exception抛出,获得了调用方法并返回方法值的机会
}
}
enter catch field 1
public static int catchTest() {
int res = 0;
try {
res = 10 / 0; // 抛出Exception,后续处理被拒绝
enterTryMethod();
return res; // Exception已经抛出,没有获得被执行的机会
} catch (Exception e) {
enterExceptionMethod();
return 1; // Exception抛出,获得了调用方法并返回方法值的机会
} finally {
enterFinallyMethod(); // Exception抛出,finally代码将在catch执行return之前被执行
}
}
enter catch field enter finally method 1
public static int catchTest() {
int res = 0;
try {
res = 10 / 2; // 不抛出Exception
enterTryMethod();
return res; // 获得被执行的机会,但执行需要在finally执行完成之后才能被执行
} catch (Exception e) {
enterExceptionMethod();
return 1;
} finally {
enterFinallyMethod();
return 1000; // finally中含有return语句,这个return将结束这个方法,不会在执行完之后再跳回try或者catch继续执行,方法到此结束
}
}
enter after try field enter finally method 1000
public static int catchTest() {
int res = 0;
try {
res = 10 / 2; // 不抛出Exception
enterTryMethod();
return res; // 获得被执行的机会,但由于finally已经终止程序,返回值没有机会被返回
} catch (Exception e) {
enterExceptionMethod();
return 1;
} finally {
enterFinallyMethod();
System.exit(0); // finally中含有System.exit()语句,System.exit()将退出整个程序,程序将被终止
}
}
enter after try field enter finally method
public static int catchTest() {
int res = 0;
try {
res = 10 / 0; // 抛出Exception,后续处理将被拒绝
enterTryMethod();
return res; // Exception已经抛出,没有获得被执行的机会
} catch (Exception e) {
enterExceptionMethod();
return 1; // Exception已经抛出,获得被执行的机会,但返回操作将被finally截断
} finally {
enterFinallyMethod();
return 10; // return将结束整个方法,返回值为10
}
}
enter catch field enter finally method 10
public static int catchTest() {
int res = 0;
try {
res = 10 / 2; // 不抛出Exception
enterTryMethod();
return res; // 获得执行机会,但返回将被finally截断
} catch (Exception e) {
enterExceptionMethod();
return 1;
} finally {
enterFinallyMethod();
return 10; // return将结束整个方法,返回值为10
}
}
enter after try field enter finally method 10
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-3 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.yuanmawang.com) 版权所有