Java Reference
In-Depth Information
Self-Test Exercises
(continued)
super
("Test Exception thrown!");
System.out.println(
"Test
exception
thrown!!");
}
public
TestException(String message)
{
super
(message);
System.out.println(
"Test exception thrown with an argument!");
}
public void
testMethod()
{
System.out.println("Message is " + getMessage());
}
}
What output would be produced by the following code (which is just an exercise and
not likely to occur in a program)?
TestException exceptionObject =
new
TestException();
System.out.println(exceptionObject.getMessage());
exceptionObject.testMethod();
The class
TestException
is on the CD that comes with this text.
14. Suppose the exception class
MyException
is defined as follows:
extra code
on CD
public class
MyException
extends
Exception
{
public
MyException()
{
super
("My Exception thrown!");
}
public
MyException(String message)
{
super
("MyException: " + message);
}
}
What output would be produced by the following code (which is just an exercise and
not likely to occur in a program)?
int
number;
try
{