File tree 2 files changed +24
-1
lines changed
src/com/deepak/ctci/Ch13_Java
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ Java Solutions for Cracking the Coding Interview - 6th Edition
129
129
130
130
** Ch 13 - Java**
131
131
- [X] [ 01 - Private Constructor] ( ../master/src/com/deepak/ctci/Ch13_Java/Problem_01.java )
132
- - [ ] 02 - Return from Finally
132
+ - [X] [ 02 - Return from Finally] ( ../master/src/com/deepak/ctci/Ch13_Java/Problem_02.java )
133
133
- [ ] 03 - Final etc
134
134
- [ ] 04 - Generics v/s Templates
135
135
- [ ] 05 - TreeMap, HashMap, LinkedHashMap
Original file line number Diff line number Diff line change 16
16
*/
17
17
public class Problem_02 {
18
18
19
+ /* Yes, finally block will always be executed even if try block has,
20
+ * 1. return statement
21
+ * 2. exception
22
+ * 3. break statement
23
+ * 4. continue statement
24
+ *
25
+ * There are only 2 possible ways where a finally block may not get executed. They are,
26
+ * 1. If the child thread processing the try block dies.
27
+ * 2. if the VM executing the process, gets killed */
28
+
29
+ public static void main (String [] args ) {
30
+ int x = 0 ;
31
+ int y = 5 ;
32
+ try {
33
+ int result = y /x ;
34
+ System .out .println ("Divison success !!. Result : " + result );
35
+ } catch (Exception exception ) {
36
+ System .out .println ("Exception occured. Message : " + exception .getMessage ());
37
+ } finally {
38
+ System .out .println ("Finally block executed even when there was a exception in try block !!" );
39
+ }
40
+ }
41
+
19
42
}
You can’t perform that action at this time.
0 commit comments