Skip to content

Commit 54fe22d

Browse files
author
zack.zhang
committed
java/se: add tcf note and exception flow
1 parent d7f13f9 commit 54fe22d

File tree

1 file changed

+75
-0
lines changed
  • java/javase/javase-syntax/src/main/java/cn/edu/ntu/javase/syntax/tcf

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package cn.edu.ntu.javase.syntax.tcf;
2+
3+
import cn.edu.ntu.javase.common.model.Person;
4+
import lombok.extern.slf4j.Slf4j;
5+
6+
/**
7+
* https://mp.weixin.qq.com/s/5XZUUpKQElTxNtbFo7IDNQ
8+
*
9+
* @author asd <br>
10+
* @create 2022-10-10 02:08 PM <br>
11+
* @project javase <br>
12+
*/
13+
@Slf4j
14+
public class ReturnTest {
15+
16+
public static void main(String[] args) {
17+
System.out.println(tcfc());
18+
System.out.println(tcff());
19+
System.out.println(tcfcf());
20+
System.out.println(tcfcf2());
21+
}
22+
23+
// 10
24+
public static int tcfc() {
25+
int a = 10;
26+
try {
27+
int i = 1 / 0;
28+
} catch (Exception e) {
29+
return a;
30+
} finally {
31+
a = 20;
32+
}
33+
return 0;
34+
}
35+
36+
// 28
37+
public static Person tcff() {
38+
Person p = new Person();
39+
p.setAge(18);
40+
try {
41+
int i = 1 / 0;
42+
} catch (Exception e) {
43+
return p;
44+
} finally {
45+
p.setAge(28);
46+
}
47+
return null;
48+
}
49+
50+
// 2
51+
public static int tcfcf() {
52+
int a = 10;
53+
try {
54+
int i = 1 / 0;
55+
} catch (Exception e) {
56+
return a;
57+
} finally {
58+
return 2;
59+
}
60+
}
61+
62+
// 30
63+
public static int tcfcf2() {
64+
int a = 10;
65+
try {
66+
int i = 1 / 0;
67+
} catch (Exception e) {
68+
a = 20;
69+
return a;
70+
} finally {
71+
a = 30;
72+
return a;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)