KaiquanMah commited on
Commit
29a26c5
·
verified ·
1 Parent(s): 0dd8036

public CustomException(String msg) { super(msg); }

Browse files
Week 5: Class hierarchies/14B. Own Exceptions 1: SuperException ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Write a class SuperException which inherits the Exception class.
2
+
3
+ Class should have a constructor which receives a message as a string.
4
+ Constructor should call the super class constructor and pass the message.
5
+
6
+ No other functionality is required.
7
+
8
+
9
+
10
+ import java.util.Random;
11
+
12
+ public class Test{
13
+ public static void main(String[] args){
14
+ final Random r = new Random();
15
+
16
+ }
17
+ }
18
+
19
+ //ADD
20
+ class SuperException extends Exception {
21
+ public SuperException(String message) {
22
+ super(message);
23
+ }
24
+ }
25
+
26
+
27
+
28
+
29
+ Testing class SuperException...
30
+ Exception object created with message "Exception thrown!"
31
+ Reading message: Exception thrown!
32
+
33
+ Trying to throw and catch exception...
34
+ Caught exception!
35
+ Message: Thrown again!
36
+
37
+
38
+
39
+