Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/lang/ClassNotFoundException.java
38829 views
/*1* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627/**28* Thrown when an application tries to load in a class through its29* string name using:30* <ul>31* <li>The <code>forName</code> method in class <code>Class</code>.32* <li>The <code>findSystemClass</code> method in class33* <code>ClassLoader</code> .34* <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.35* </ul>36* <p>37* but no definition for the class with the specified name could be found.38*39* <p>As of release 1.4, this exception has been retrofitted to conform to40* the general purpose exception-chaining mechanism. The "optional exception41* that was raised while loading the class" that may be provided at42* construction time and accessed via the {@link #getException()} method is43* now known as the <i>cause</i>, and may be accessed via the {@link44* Throwable#getCause()} method, as well as the aforementioned "legacy method."45*46* @author unascribed47* @see java.lang.Class#forName(java.lang.String)48* @see java.lang.ClassLoader#findSystemClass(java.lang.String)49* @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)50* @since JDK1.051*/52public class ClassNotFoundException extends ReflectiveOperationException {53/**54* use serialVersionUID from JDK 1.1.X for interoperability55*/56private static final long serialVersionUID = 9176873029745254542L;5758/**59* This field holds the exception ex if the60* ClassNotFoundException(String s, Throwable ex) constructor was61* used to instantiate the object62* @serial63* @since 1.264*/65private Throwable ex;6667/**68* Constructs a <code>ClassNotFoundException</code> with no detail message.69*/70public ClassNotFoundException() {71super((Throwable)null); // Disallow initCause72}7374/**75* Constructs a <code>ClassNotFoundException</code> with the76* specified detail message.77*78* @param s the detail message.79*/80public ClassNotFoundException(String s) {81super(s, null); // Disallow initCause82}8384/**85* Constructs a <code>ClassNotFoundException</code> with the86* specified detail message and optional exception that was87* raised while loading the class.88*89* @param s the detail message90* @param ex the exception that was raised while loading the class91* @since 1.292*/93public ClassNotFoundException(String s, Throwable ex) {94super(s, null); // Disallow initCause95this.ex = ex;96}9798/**99* Returns the exception that was raised if an error occurred while100* attempting to load the class. Otherwise, returns <tt>null</tt>.101*102* <p>This method predates the general-purpose exception chaining facility.103* The {@link Throwable#getCause()} method is now the preferred means of104* obtaining this information.105*106* @return the <code>Exception</code> that was raised while loading a class107* @since 1.2108*/109public Throwable getException() {110return ex;111}112113/**114* Returns the cause of this exception (the exception that was raised115* if an error occurred while attempting to load the class; otherwise116* <tt>null</tt>).117*118* @return the cause of this exception.119* @since 1.4120*/121public Throwable getCause() {122return ex;123}124}125126127