打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
TestTryCatch.java
package combaidu;

public class TestTryCatch {
static int doMethod1() { // 11
int a = 10;
try {
a++;
} finally {
return a;
}
}

// =================================================================
static int doMethod2() { // 10
int a = 10;
try {
return a; // @AfterReturn
// 两个步骤(
// 步骤一获取a的值,存储a的值给给临时变量temp
// 步骤二返回临时变量temp的值(finally执行结束执行))
} finally { // @After
System.out.println("doMethod2()...");
a++;
}
}

// ============================================================
static int doMethod3() {
int a = 10;
try {
// 故意试错,大家可以Debug  F5,F6,F7测试前后顺序
int b = a / 0;  //  1............
return a;// @AfterReturn
// 两个步骤(
// 步骤一获取a的值,存储a的值给给临时变量temp
// 步骤二返回临时变量temp的值(finally执行结束执行))
} catch (Exception e) {
throw new RuntimeException(e);
// @AfterThrowing
} finally {// @After
System.out.println("doMethod3()....");
a++;
}
}
// ======================================================

public static int doMethod4() { //20
try {
return 10;
} finally {
return 20;
}
}

// ======================================================

public static void main(String[] args) {
//int result = doMethod1();
//System.out.println("doMethod1..="+result);
int result1 = doMethod2();
System.out.println("doMethod2..="+result1);
// int result2 = doMethod3();
// System.out.println("doMethod3..="+result2);
//int result3 = doMethod4();
//System.out.println("doMethod4..="+result3);
}
}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Java关键字之native,strictfp,transient,volatile - OO - Java - ITeye论坛
java基础知识(四)
大数据Java篇--变换变量的三种方式
java中关于方法参数的介绍
java 插入排序
面试考代码,居然翻车了!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服