forked from LuigiCortese/java-certification-ocp8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.java
42 lines (33 loc) · 924 Bytes
/
App.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
package net.devsedge.exception.trycatch;
/**
*
* @author Luigi Cortese
*
*/
public class App {
public static void main(String[] args) throws E1, E2 {
foo();
}
static void foo() throws E1,E2{
try{
bar();
}catch(Exception e){
/*
* This catch is not catching all exceptions, but here "Exception" is
* <<any exceptions that bar() happens to throw>>.
* This is equivalent to
* catch(E1|E2 e)
*/
//CASE 1
// throw new Exception(); //won't compile
//CASE 2
// e=null; //causes next row not to compile. Being this case equivalent to a
//multicatch, in multicatch variable is final. If you now reassing
//the variable, you're going back to classical non-multicatch.
throw e; //won't compile in Java 6
}
}
static void bar() throws E1,E2{}
}
class E1 extends Exception{}
class E2 extends Exception{}