emul/mini/src/main/java/java/lang/ClassNotFoundException.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 26 Jan 2013 08:47:05 +0100
changeset 592 5e13b1ac2886
parent 66 8a74b5d8d1d4
permissions -rw-r--r--
In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
jaroslav@66
     1
/*
jaroslav@66
     2
 * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
jaroslav@66
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@66
     4
 *
jaroslav@66
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@66
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@66
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@66
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@66
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@66
    10
 *
jaroslav@66
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@66
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@66
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@66
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@66
    15
 * accompanied this code).
jaroslav@66
    16
 *
jaroslav@66
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@66
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@66
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@66
    20
 *
jaroslav@66
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@66
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@66
    23
 * questions.
jaroslav@66
    24
 */
jaroslav@66
    25
jaroslav@66
    26
package java.lang;
jaroslav@66
    27
jaroslav@66
    28
/**
jaroslav@66
    29
 * Thrown when an application tries to load in a class through its
jaroslav@66
    30
 * string name using:
jaroslav@66
    31
 * <ul>
jaroslav@66
    32
 * <li>The <code>forName</code> method in class <code>Class</code>.
jaroslav@66
    33
 * <li>The <code>findSystemClass</code> method in class
jaroslav@66
    34
 *     <code>ClassLoader</code> .
jaroslav@66
    35
 * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
jaroslav@66
    36
 * </ul>
jaroslav@66
    37
 * <p>
jaroslav@66
    38
 * but no definition for the class with the specified name could be found.
jaroslav@66
    39
 *
jaroslav@66
    40
 * <p>As of release 1.4, this exception has been retrofitted to conform to
jaroslav@66
    41
 * the general purpose exception-chaining mechanism.  The "optional exception
jaroslav@66
    42
 * that was raised while loading the class" that may be provided at
jaroslav@66
    43
 * construction time and accessed via the {@link #getException()} method is
jaroslav@66
    44
 * now known as the <i>cause</i>, and may be accessed via the {@link
jaroslav@66
    45
 * Throwable#getCause()} method, as well as the aforementioned "legacy method."
jaroslav@66
    46
 *
jaroslav@66
    47
 * @author  unascribed
jaroslav@66
    48
 * @see     java.lang.Class#forName(java.lang.String)
jaroslav@66
    49
 * @see     java.lang.ClassLoader#findSystemClass(java.lang.String)
jaroslav@66
    50
 * @see     java.lang.ClassLoader#loadClass(java.lang.String, boolean)
jaroslav@66
    51
 * @since   JDK1.0
jaroslav@66
    52
 */
jaroslav@66
    53
public class ClassNotFoundException extends ReflectiveOperationException {
jaroslav@66
    54
    /**
jaroslav@66
    55
     * use serialVersionUID from JDK 1.1.X for interoperability
jaroslav@66
    56
     */
jaroslav@66
    57
     private static final long serialVersionUID = 9176873029745254542L;
jaroslav@66
    58
jaroslav@66
    59
    /**
jaroslav@66
    60
     * This field holds the exception ex if the
jaroslav@66
    61
     * ClassNotFoundException(String s, Throwable ex) constructor was
jaroslav@66
    62
     * used to instantiate the object
jaroslav@66
    63
     * @serial
jaroslav@66
    64
     * @since 1.2
jaroslav@66
    65
     */
jaroslav@66
    66
    private Throwable ex;
jaroslav@66
    67
jaroslav@66
    68
    /**
jaroslav@66
    69
     * Constructs a <code>ClassNotFoundException</code> with no detail message.
jaroslav@66
    70
     */
jaroslav@66
    71
    public ClassNotFoundException() {
jaroslav@66
    72
        super((Throwable)null);  // Disallow initCause
jaroslav@66
    73
    }
jaroslav@66
    74
jaroslav@66
    75
    /**
jaroslav@66
    76
     * Constructs a <code>ClassNotFoundException</code> with the
jaroslav@66
    77
     * specified detail message.
jaroslav@66
    78
     *
jaroslav@66
    79
     * @param   s   the detail message.
jaroslav@66
    80
     */
jaroslav@66
    81
    public ClassNotFoundException(String s) {
jaroslav@66
    82
        super(s, null);  //  Disallow initCause
jaroslav@66
    83
    }
jaroslav@66
    84
jaroslav@66
    85
    /**
jaroslav@66
    86
     * Constructs a <code>ClassNotFoundException</code> with the
jaroslav@66
    87
     * specified detail message and optional exception that was
jaroslav@66
    88
     * raised while loading the class.
jaroslav@66
    89
     *
jaroslav@66
    90
     * @param s the detail message
jaroslav@66
    91
     * @param ex the exception that was raised while loading the class
jaroslav@66
    92
     * @since 1.2
jaroslav@66
    93
     */
jaroslav@66
    94
    public ClassNotFoundException(String s, Throwable ex) {
jaroslav@66
    95
        super(s, null);  //  Disallow initCause
jaroslav@66
    96
        this.ex = ex;
jaroslav@66
    97
    }
jaroslav@66
    98
jaroslav@66
    99
    /**
jaroslav@66
   100
     * Returns the exception that was raised if an error occurred while
jaroslav@66
   101
     * attempting to load the class. Otherwise, returns <tt>null</tt>.
jaroslav@66
   102
     *
jaroslav@66
   103
     * <p>This method predates the general-purpose exception chaining facility.
jaroslav@66
   104
     * The {@link Throwable#getCause()} method is now the preferred means of
jaroslav@66
   105
     * obtaining this information.
jaroslav@66
   106
     *
jaroslav@66
   107
     * @return the <code>Exception</code> that was raised while loading a class
jaroslav@66
   108
     * @since 1.2
jaroslav@66
   109
     */
jaroslav@66
   110
    public Throwable getException() {
jaroslav@66
   111
        return ex;
jaroslav@66
   112
    }
jaroslav@66
   113
jaroslav@66
   114
    /**
jaroslav@66
   115
     * Returns the cause of this exception (the exception that was raised
jaroslav@66
   116
     * if an error occurred while attempting to load the class; otherwise
jaroslav@66
   117
     * <tt>null</tt>).
jaroslav@66
   118
     *
jaroslav@66
   119
     * @return  the cause of this exception.
jaroslav@66
   120
     * @since   1.4
jaroslav@66
   121
     */
jaroslav@66
   122
    public Throwable getCause() {
jaroslav@66
   123
        return ex;
jaroslav@66
   124
    }
jaroslav@66
   125
}