public class OutOfRangeException extends Exception // we expect a certain range of int values from rangeMin to rangeMax { private String variableName; private int variableValue, rangeMin, rangeMax; public OutOfRangeException() // no arg constructor, we have no idea what variable or value was used { super("Out of range Exception generated"); variableValue=rangeMin=rangeMax=0; variableName=""; } public OutOfRangeException(String var, int value) // we know the variable name and value but not the range { super(var + " has value " + value + " which is out of range"); variableName=var; variableValue=value; rangeMin=rangeMax=0; } public OutOfRangeException(String var, int value, int min) // we know the variable name, value and the minimum in the range but not the max { super(var + " has value " + value + " which needs to be at least " + min); variableName=var; variableValue=value; rangeMin=min; rangeMax=Integer.MAX_VALUE; } public OutOfRangeException(String var, int value, int min, int max) // we know all of the info { super(var + " has value " + value + " which is out of the acceptable range of " + min + " to " + max); variableName=var; variableValue=value; rangeMin=min; rangeMax=max; } public void setMin(int min) // setter in case the Exception was created without a min value { rangeMin=min; } public void setMax(int max) // setter in case the Exception was created without a max value { rangeMax=max; } // accessors public int getValue() {return variableValue;} public int getMin() {return rangeMin;} public int getMax() {return rangeMax;} public String getVariableName() {return variableName;} // this toString can be risky as we may not know rangeMin and rangeMax in which case the output may not make sense! public String toString() {return variableName + " has value " + variableValue + " which is out of the acceptable range of " + rangeMin + " to " + rangeMax;} }