NegativeLengthException.java Illustrates defining and throwing your own exceptions.

import java.io.*;

/** Taken from Core Web Programming from
 *  Prentice Hall and Sun Microsystems Press,
 *  .
 *  © 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted.
 */

public class NegativeLengthException extends Exception {

  /** Test NegativeLengthException */

  public static void main(String[] args) {
    try {
      int lineLength = readLength();
      for(int i=0; i

Permanent link to this article: http://bangla.sitestree.com/negativelengthexception-java-illustrates-defining-and-throwing-your-own-exceptions/

Leave a Reply