TurkuBasicOOPinJava / Week 5: Class hierarchies /14B. Own Exceptions 1: SuperException
KaiquanMah's picture
public CustomException(String msg) { super(msg); }
29a26c5 verified
raw
history blame
734 Bytes
Write a class SuperException which inherits the Exception class.
Class should have a constructor which receives a message as a string.
Constructor should call the super class constructor and pass the message.
No other functionality is required.
import java.util.Random;
public class Test{
public static void main(String[] args){
final Random r = new Random();
}
}
//ADD
class SuperException extends Exception {
public SuperException(String message) {
super(message);
}
}
Testing class SuperException...
Exception object created with message "Exception thrown!"
Reading message: Exception thrown!
Trying to throw and catch exception...
Caught exception!
Message: Thrown again!