-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestFinally.java
More file actions
executable file
·90 lines (79 loc) · 2.37 KB
/
TestFinally.java
File metadata and controls
executable file
·90 lines (79 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/** îòîáðàæåíèå ðàçëè÷íûõ ñèòóàöèé, êîòîðûå ìîãóò èìåòü ìåñòî ïðè èñïîëüçîâàíèè êîíñòðóêöèè finally*/
public class TestFinally {
/** äåìîíñòðàöèÿ ïîòåðÿííîãî èñêëþ÷åíèÿ */
private static void lostException() throws Exception {
try{
System.out.println("try block");
throw new Exception("try Exception ");
}catch(Exception ex){
System.out.println("catch block");
// this exception was failed
throw new Exception("catch Exception");
}finally{
System.out.println("finally block");
throw new Exception("finally Exception");
}
}
/** äåìîíñòðàöèÿ ïîòåðÿííîãî èñêëþ÷åíèÿ */
private static void lostException2() throws Exception {
try{
System.out.println("try block");
throw new Exception("try Exception ");
}finally{
System.out.println("finally block");
throw new Exception("finally Exception ");
}
}
/** äåìîíñòðàöèÿ íåóäàâøåãîñÿ âîçâðàòà ôóíêöèè */
private static int lostReturn(){
try{
System.out.println("try");
return 5;
}finally{
System.out.println("finally");
// try remark finally return
return 999;
}
}
/** äåìîíñòðàöèÿ íåóäàâøåãîñÿ âîçâðàòà ôóíêöèè */
private static int lostReturn2(boolean value){
try{
System.out.println("try");
if(value==true){
throw new Exception();
}else{
return 5;
}
}catch(Exception ex){
System.out.println("catch");
return 22;
}finally{
System.out.println("finally");
// try remark finally return
//return 999;
}
//return 7;
}
public static void main(String[] args){
System.out.println("Demonstration lost exception BEGIN:");
try{
lostException();
}catch(Exception ex){
System.out.println("Main:"+ex.getMessage());
}
System.out.println("Demonstration lost exception END:");
System.out.println("Demonstration lost exception 2 BEGIN:");
try{
lostException2();
}catch(Exception ex){
System.out.println("Main:"+ex.getMessage());
}
System.out.println("Demonstration lost exception 2 END:\n\n\n");
System.out.println("Demonstration lost Return BEGIN:");
System.out.println(lostReturn());
System.out.println("Demonstration lost Return END: ");
System.out.println("Demonstration lost Return 2 BEGIN:");
System.out.println(lostReturn2(false));
System.out.println("Demonstration lost Return 2 END: ");
}
}