-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHuman.java
More file actions
47 lines (40 loc) · 1.02 KB
/
Human.java
File metadata and controls
47 lines (40 loc) · 1.02 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
43
44
45
46
47
package exceptions;
/**
* RUN:
* javac exceptions/Human.java && java exceptions.Human
* OUTPUT:
* exceptions\Human.java:25: warning: unreachable catch clause
* catch(Annoyance a) {
* ^
* thrown type Sneeze has already been caught
* 1 warning
*
* Catched Sneeze
* Catched Annoyance
*/
// import java.util.logging.*;
// import java.io.*;
public class Human {
public static void main(String[] args)
{
// catch original exception
try {
throw new Sneeze();
}
catch(Sneeze s) {
System.out.println("Catched Sneeze");
}
catch(Annoyance a) {
System.out.println("Catched Annoyance");
}
// catch base exception
try {
throw new Sneeze();
}
catch(Annoyance a) {
System.out.println("Catched Annoyance");
}
}
}
class Annoyance extends Exception {}
class Sneeze extends Annoyance {}