Hello!
In chapter 7 on page 300 near the bottom, in regards to instantiating an object of your own exception type (derived from "Exception") by calling its empty default constructor, it says:
Quote:
|
The message in the exception object consists only of the qualified name of the exception class.
|
So, if I do the following:
Code:
MyException e = new MyException();
,,,and the default constructor for "MyException" is just empty, I would expect "e" to have a message that consists of the qualified name of the exception class. However, in my code below, the message is null. Am I missing something?
Code:
public class MyException extends Exception {
public MyException() { } // Empty default constructor.
public MyException(String message) {
super(message);
// ...
}
}
public class TryThis {
public static void main(String[] args) {
try {
throw new MyException(); // Call the default constructor.
} catch (MyException e) {
System.err.println(e.getMessage()); // Prints "null"!
}
}
}