Although an exception class normally carries only a string message, you can
define exception classes to carry a message of any type. For example, objects of
the following type can also carry a double “message” (as well as a string message):
public class DoubleException extends Exception
{
private double doubleMessage;
public DoubleException()
{
super("DoubleException thrown!");
}
public DoubleException(String message)
{
super(message);
}
public DoubleException(double number)
{
super("DoubleException thrown!");
doubleMessage = number;
}
public double getNumber()
{
return doubleMessage;
}
}
What output would be produced by the following code (which is just an
exercise and not likely to occur in a program)?
DoubleException e =
new DoubleException(41.9);
System.out.println(e.getNumber());
System.out.println(e.getMessage());
The class DoubleException is on the website that comes with this text.