-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFinallyDemo.java
More file actions
47 lines (39 loc) · 999 Bytes
/
FinallyDemo.java
File metadata and controls
47 lines (39 loc) · 999 Bytes
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
package chapter10;
//Demonstrate finally
public class FinallyDemo {
//throw an exception out of the method.
static void procA() {
try {
System.out.println("Inside procA");
throw new RuntimeException("demo");
} finally {
System.out.println("procA's finally");
}
}
//Return within a try block
static void procB() {
try {
System.out.println("Inside procB");
return;
} finally {
System.out.println("ProcB's finally");
}
}
//Execute try block normally
static void procC() {
try {
System.out.println("Inside procC");
} finally {
System.out.println("ProcC's finally");
}
}
public static void main(String[] args) {
try {
procA();
} catch (Exception e) {
System.out.println("Exception caught " + e);
}
procB();
procC();
}
}