Writing Exception Subclasses

Most exception subclasses inherit all their functionality from the superclass. Each subclass mainly serves as a marker for a different kind of exception. However it only rarely provides new methods or fields. Thus most of the time the only methods you need to implement are the constructors. There should be one noargs constructor and one constructor that takes a String message as an argument. These will mostly just invoke the matching superclass constructor.

public class ClockException extends Exception {

  public ClockException(String message) {
    super(message);
  }

  public ClockException() {
    super();
  }

}

Previous | Next | Top | Cafe au Lait

Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 9, 1999