jaroslav@66: /* jaroslav@66: * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved. jaroslav@66: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@66: * jaroslav@66: * This code is free software; you can redistribute it and/or modify it jaroslav@66: * under the terms of the GNU General Public License version 2 only, as jaroslav@66: * published by the Free Software Foundation. Oracle designates this jaroslav@66: * particular file as subject to the "Classpath" exception as provided jaroslav@66: * by Oracle in the LICENSE file that accompanied this code. jaroslav@66: * jaroslav@66: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@66: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@66: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@66: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@66: * accompanied this code). jaroslav@66: * jaroslav@66: * You should have received a copy of the GNU General Public License version jaroslav@66: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@66: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@66: * jaroslav@66: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@66: * or visit www.oracle.com if you need additional information or have any jaroslav@66: * questions. jaroslav@66: */ jaroslav@66: jaroslav@66: package java.lang; jaroslav@66: jaroslav@66: /** jaroslav@66: * Thrown when an application tries to load in a class through its jaroslav@66: * string name using: jaroslav@66: *
forName
method in class Class
.
jaroslav@66: * findSystemClass
method in class
jaroslav@66: * ClassLoader
.
jaroslav@66: * loadClass
method in class ClassLoader
.
jaroslav@66: * jaroslav@66: * but no definition for the class with the specified name could be found. jaroslav@66: * jaroslav@66: *
As of release 1.4, this exception has been retrofitted to conform to
jaroslav@66: * the general purpose exception-chaining mechanism. The "optional exception
jaroslav@66: * that was raised while loading the class" that may be provided at
jaroslav@66: * construction time and accessed via the {@link #getException()} method is
jaroslav@66: * now known as the cause, and may be accessed via the {@link
jaroslav@66: * Throwable#getCause()} method, as well as the aforementioned "legacy method."
jaroslav@66: *
jaroslav@66: * @author unascribed
jaroslav@66: * @see java.lang.Class#forName(java.lang.String)
jaroslav@66: * @see java.lang.ClassLoader#findSystemClass(java.lang.String)
jaroslav@66: * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
jaroslav@66: * @since JDK1.0
jaroslav@66: */
jaroslav@66: public class ClassNotFoundException extends ReflectiveOperationException {
jaroslav@66: /**
jaroslav@66: * use serialVersionUID from JDK 1.1.X for interoperability
jaroslav@66: */
jaroslav@66: private static final long serialVersionUID = 9176873029745254542L;
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * This field holds the exception ex if the
jaroslav@66: * ClassNotFoundException(String s, Throwable ex) constructor was
jaroslav@66: * used to instantiate the object
jaroslav@66: * @serial
jaroslav@66: * @since 1.2
jaroslav@66: */
jaroslav@66: private Throwable ex;
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * Constructs a ClassNotFoundException
with no detail message.
jaroslav@66: */
jaroslav@66: public ClassNotFoundException() {
jaroslav@66: super((Throwable)null); // Disallow initCause
jaroslav@66: }
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * Constructs a ClassNotFoundException
with the
jaroslav@66: * specified detail message.
jaroslav@66: *
jaroslav@66: * @param s the detail message.
jaroslav@66: */
jaroslav@66: public ClassNotFoundException(String s) {
jaroslav@66: super(s, null); // Disallow initCause
jaroslav@66: }
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * Constructs a ClassNotFoundException
with the
jaroslav@66: * specified detail message and optional exception that was
jaroslav@66: * raised while loading the class.
jaroslav@66: *
jaroslav@66: * @param s the detail message
jaroslav@66: * @param ex the exception that was raised while loading the class
jaroslav@66: * @since 1.2
jaroslav@66: */
jaroslav@66: public ClassNotFoundException(String s, Throwable ex) {
jaroslav@66: super(s, null); // Disallow initCause
jaroslav@66: this.ex = ex;
jaroslav@66: }
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * Returns the exception that was raised if an error occurred while
jaroslav@66: * attempting to load the class. Otherwise, returns null.
jaroslav@66: *
jaroslav@66: *
This method predates the general-purpose exception chaining facility.
jaroslav@66: * The {@link Throwable#getCause()} method is now the preferred means of
jaroslav@66: * obtaining this information.
jaroslav@66: *
jaroslav@66: * @return the Exception
that was raised while loading a class
jaroslav@66: * @since 1.2
jaroslav@66: */
jaroslav@66: public Throwable getException() {
jaroslav@66: return ex;
jaroslav@66: }
jaroslav@66:
jaroslav@66: /**
jaroslav@66: * Returns the cause of this exception (the exception that was raised
jaroslav@66: * if an error occurred while attempting to load the class; otherwise
jaroslav@66: * null).
jaroslav@66: *
jaroslav@66: * @return the cause of this exception.
jaroslav@66: * @since 1.4
jaroslav@66: */
jaroslav@66: public Throwable getCause() {
jaroslav@66: return ex;
jaroslav@66: }
jaroslav@66: }