home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / lang / ClassNotFoundException.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.9 KB  |  146 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)ClassNotFoundException.java    1.8 98/05/04
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang;
  16.  
  17. import java.io.PrintStream;
  18. import java.io.PrintWriter;
  19.  
  20. /**
  21.  * Thrown when an application tries to load in a class through its 
  22.  * string name using:
  23.  * <ul>
  24.  * <li>The <code>forName</code> method in class <code>Class</code>.
  25.  * <li>The <code>findSystemClass</code> method in class
  26.  *     <code>ClassLoader</code> .
  27.  * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  28.  * </ul>
  29.  * <p>
  30.  * but no definition for the class with the specifed name could be found. 
  31.  *
  32.  * @author  unascribed
  33.  * @version 1.8, 05/04/98
  34.  * @see     java.lang.Class#forName(java.lang.String)
  35.  * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
  36.  * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  37.  * @since   JDK1.0
  38.  */
  39. public
  40. class ClassNotFoundException extends Exception {
  41.     /**
  42.      * use serialVersionUID from JDK 1.1.X for interoperability
  43.      */
  44.      private static final long serialVersionUID = 9176873029745254542L;
  45.  
  46.     /**
  47.      * This field holds the exception ex if the 
  48.      * ClassNotFoundException(String s, Throwable ex) constructor was
  49.      * used to instantiate the object
  50.      * @serial 
  51.      * @since JDK 1.2
  52.      */
  53.     private Throwable ex;
  54.  
  55.     /**
  56.      * Constructs a <code>ClassNotFoundException</code> with no detail message.
  57.      */
  58.     public ClassNotFoundException() {
  59.     super();
  60.     }
  61.  
  62.     /**
  63.      * Constructs a <code>ClassNotFoundException</code> with the 
  64.      * specified detail message. 
  65.      *
  66.      * @param   s   the detail message.
  67.      */
  68.     public ClassNotFoundException(String s) {
  69.     super(s);
  70.     }
  71.  
  72.     /**
  73.      * Constructs a <code>ClassNotFoundException</code> with the
  74.      * specified detail message and optional exception that was
  75.      * raised while loading the class.
  76.      *
  77.      * @param s the detail message
  78.      * @param ex the exception that was raised while loading the class
  79.      * @since JDK1.2
  80.      */
  81.     public ClassNotFoundException(String s, Throwable ex) {
  82.     super(s);
  83.     this.ex = ex;
  84.     }
  85.  
  86.     /**
  87.      * Returns the exception that was raised if an error occurred while
  88.      * attempting to load the class. Otherwise, returns null.
  89.      *
  90.      * @since JDK1.2
  91.      */
  92.     public Throwable getException() {
  93.     return ex;
  94.     }
  95.  
  96.     /**
  97.      * Prints the stack backtrace. 
  98.      * 
  99.      * If an exception occurred during class loading it prints that
  100.      * exception's stack trace, or else prints the stack backtrace of
  101.      * this exception.
  102.      *
  103.      * @see java.lang.System#err
  104.      */
  105.     public void printStackTrace() { 
  106.     printStackTrace(System.err);
  107.     }
  108.     
  109.     /**
  110.      * Prints the stack backtrace to the specified print stream.
  111.      *
  112.      * If an exception occurred during class loading it prints that
  113.      * exception's stack trace, or else prints the stack backtrace of
  114.      * this exception.
  115.      */
  116.     public void printStackTrace(PrintStream ps) { 
  117.     synchronized (ps) {
  118.         if (ex != null) {
  119.         ps.print("java.lang.ClassNotFoundException: ");
  120.         ex.printStackTrace(ps);
  121.         } else {
  122.         super.printStackTrace(ps);
  123.         }
  124.     }
  125.     }
  126.     
  127.     /**
  128.      * Prints the stack backtrace to the specified print writer.
  129.      *
  130.      * If an exception occurred during class loading it prints that
  131.      * exception's stack trace, or else prints the stack backtrace of
  132.      * this exception.
  133.      */
  134.     public void printStackTrace(PrintWriter pw) { 
  135.     synchronized (pw) {
  136.         if (ex != null) {
  137.         pw.print("java.lang.ClassNotFoundException: ");
  138.         ex.printStackTrace(pw);
  139.         } else {
  140.         super.printStackTrace(pw);
  141.         }
  142.     }
  143.     }
  144.  
  145. }
  146.