// Filename Counters/CounterException.java. // Providing an extension of the RuntimeException class // for use with the Counter hierarchy // // Written for JFL book Chapter 4 see text. // Fintan Culwin, v0.1, January 1997 public class CounterException extends RuntimeException { static final int EXIT = 0; // different actions taken static final int WARNING = 1; static final int PASS = 2; static int exceptionCount = 0; public CounterException( int code, String reason ) { exceptionCount ++; // mmm, another exception coming in. if (code == EXIT) // very bad, throw exception, exit program throw new RuntimeException( reason ); else if (code == WARNING)// well, give them a warning System.err.println("WARNING: " + reason); // else just keep it quiet } // End CounterException constructor public CounterException(String reason ) { // constructor with a reason exceptionCount ++; // mmm, another exception coming in. throw new RuntimeException( reason ); } // End CounterException constructor public CounterException() { // constructor without a reason exceptionCount ++; // mmm, another exception coming in. throw new RuntimeException("Counter Exception is encounted\n"); } // End CounterException constructor } // End CounterException