-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTrickyFinally.java
58 lines (52 loc) · 1.3 KB
/
TrickyFinally.java
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
package by.andd3dfx.core;
/**
* Какую из трёх исключительных ситуаций мы получим на выходе в данном блоке кода? Почему?
* <pre>
* try {
* throw new Exception1();
* } catch (Exception ex) {
* throw new Exception2();
* } finally {
* throw new Exception3();
* }
* </pre>
* <p>
* Что будет возвращено в данном блоке кода ниже? Почему?
* <pre>
* try {
* return 1;
* } catch(Exception e) {
* return 2;
* } finally {
* return 3;
* }
* </pre>
*
* @see <a href="https://youtu.be/Man9zRalhPs">Video solution</a>
*/
public class TrickyFinally {
public void case1() throws Exception3 {
try {
throw new Exception1();
} catch (Exception ex) {
throw new Exception2();
} finally {
throw new Exception3();
}
}
public int case2() {
try {
return 1;
} catch (Exception e) {
return 2;
} finally {
return 3;
}
}
public class Exception1 extends Exception {
}
public class Exception2 extends Exception {
}
public class Exception3 extends Exception {
}
}