Suppose that, in Self-Test Question 19, we change the value of number
from 42 to −99. How would this change affect the output?
Although an exception class normally carries only a string message, you
can define exception classes to carry a message of any type. You can give
your exception class instance variables and methods. For example, objects
of the following type can also carry an int “message,” as well as a string
message:
public class IntException extends Exception
{
private int intMessage;
public IntException()
{
super("IntException thrown!");
}
public IntException(String message)
{
super(message + " " + message);
}
public IntException(int number)
{
super("IntException thrown!");
intMessage = number;
}
public int getNumber()
{
returnintMessage;
}
}
What output would be produced by the following unlikely code?
IntException e = new IntException(42);
System.out.println(e.getNumber());
System.out.println(e.getMessage());