// Filename JulianDateException.java. // Providing specific exception for JulianDate class // // Written for JFL book Chapter 9 see text. // From the JFL textbook, typed in by X. Meng package JulianDates; public class JulianDateException extends RuntimeException { public static final int NULL_DATE = 0; public static final int DATE_INPUT_ERROR = 1; public static final int ARITHMETIC_ERROR = 2; public static final int DATE_CONSTRUCTION_ERROR = 3; private int theReason; public JulianDateException( int reason) { super(); theReason = reason; } // End principal constructor public int obtainReason(){ return theReason; } // End obtainReason. public String toString(){ String toReturn; switch ( theReason) { case NULL_DATE: toReturn = new String( "JulianDate exception : Empty date."); break; case DATE_INPUT_ERROR: toReturn = new String( "JulianDate exception : Date input incorrect."); break; case ARITHMETIC_ERROR: toReturn = new String( "JulianDate exception : Arithmetic error."); break; case DATE_CONSTRUCTION_ERROR: toReturn = new String( "JulianDate exception : Constructor error."); break; default: toReturn = new String( "JulianDate exception : Unknown reason."); } // End switch. return toReturn; } // End toString. } // End JulianDateException.