KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > ClassNotFoundException


1 /*
2  * @(#)ClassNotFoundException.java 1.20 04/02/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang;
9
10 /**
11  * Thrown when an application tries to load in a class through its
12  * string name using:
13  * <ul>
14  * <li>The <code>forName</code> method in class <code>Class</code>.
15  * <li>The <code>findSystemClass</code> method in class
16  * <code>ClassLoader</code> .
17  * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
18  * </ul>
19  * <p>
20  * but no definition for the class with the specified name could be found.
21  *
22  * <p>As of release 1.4, this exception has been retrofitted to conform to
23  * the general purpose exception-chaining mechanism. The "optional exception
24  * that was raised while loading the class" that may be provided at
25  * construction time and accessed via the {@link #getException()} method is
26  * now known as the <i>cause</i>, and may be accessed via the {@link
27  * Throwable#getCause()} method, as well as the aforementioned "legacy method."
28  *
29  * @author unascribed
30  * @version 1.20, 02/19/04
31  * @see java.lang.Class#forName(java.lang.String)
32  * @see java.lang.ClassLoader#findSystemClass(java.lang.String)
33  * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
34  * @since JDK1.0
35  */

36 public class ClassNotFoundException extends Exception JavaDoc {
37     /**
38      * use serialVersionUID from JDK 1.1.X for interoperability
39      */

40      private static final long serialVersionUID = 9176873029745254542L;
41
42     /**
43      * This field holds the exception ex if the
44      * ClassNotFoundException(String s, Throwable ex) constructor was
45      * used to instantiate the object
46      * @serial
47      * @since 1.2
48      */

49     private Throwable JavaDoc ex;
50
51     /**
52      * Constructs a <code>ClassNotFoundException</code> with no detail message.
53      */

54     public ClassNotFoundException() {
55     super((Throwable JavaDoc)null); // Disallow initCause
56
}
57
58     /**
59      * Constructs a <code>ClassNotFoundException</code> with the
60      * specified detail message.
61      *
62      * @param s the detail message.
63      */

64     public ClassNotFoundException(String JavaDoc s) {
65     super(s, null); // Disallow initCause
66
}
67
68     /**
69      * Constructs a <code>ClassNotFoundException</code> with the
70      * specified detail message and optional exception that was
71      * raised while loading the class.
72      *
73      * @param s the detail message
74      * @param ex the exception that was raised while loading the class
75      * @since 1.2
76      */

77     public ClassNotFoundException(String JavaDoc s, Throwable JavaDoc ex) {
78     super(s, null); // Disallow initCause
79
this.ex = ex;
80     }
81
82     /**
83      * Returns the exception that was raised if an error occurred while
84      * attempting to load the class. Otherwise, returns <tt>null</tt>.
85      *
86      * <p>This method predates the general-purpose exception chaining facility.
87      * The {@link Throwable#getCause()} method is now the preferred means of
88      * obtaining this information.
89      *
90      * @return the <code>Exception</code> that was raised while loading a class
91      * @since 1.2
92      */

93     public Throwable JavaDoc getException() {
94         return ex;
95     }
96
97     /**
98      * Returns the cause of this exception (the exception that was raised
99      * if an error occurred while attempting to load the class; otherwise
100      * <tt>null</tt>).
101      *
102      * @return the cause of this exception.
103      * @since 1.4
104      */

105     public Throwable JavaDoc getCause() {
106         return ex;
107     }
108 }
109
Popular Tags