-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinally_Block.java
More file actions
42 lines (39 loc) · 1.1 KB
/
Copy pathFinally_Block.java
File metadata and controls
42 lines (39 loc) · 1.1 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
package BASICS;
public class Finally_Block {
public static int greet(){
try{
int a = 50;
int b = 2;
int c = a/b;
return c;
}
catch(Exception e){
System.out.println(e);
}
finally {
System.out.println("This is the end of this program"); //usually if return c gets executed
//then without finally we won't get cout
}
return 0;
}
public static void main(String[] args) {
int k = greet();
System.out.println(k);
int a = 5;
int b = 6;
while(true){
try{
System.out.println(a/b);
}
catch(Exception e){
System.out.println(e);
break;
}
finally {
System.out.println("Im finally for value of b = " + b);
// even though func ended with break, but finally got executed, even after breaking of loop
}
b--;
}
}
}