Source Home >> Java Source 1.6.0 >> java.lang.ClassNotFoundException V 0.09
  • 001/*
  • 002 * @(#)ClassNotFoundException.java 1.21 05/11/17
  • 003 *
  • 004 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  • 005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  • 006 */
  • 007
  • 008package java.lang;
  • 009
  • 010/**
  • 011 * Thrown when an application tries to load in a class through its
  • 012 * string name using:
  • 013 * <ul>
  • 014 * <li>The <code>forName</code> method in class <code>Class</code>.
  • 015 * <li>The <code>findSystemClass</code> method in class
  • 016 * <code>ClassLoader</code> .
  • 017 * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
  • 018 * </ul>
  • 019 * <p>
  • 020 * but no definition for the class with the specified name could be found.
  • 021 *
  • 022 * <p>As of release 1.4, this exception has been retrofitted to conform to
  • 023 * the general purpose exception-chaining mechanism. The "optional exception
  • 024 * that was raised while loading the class" that may be provided at
  • 025 * construction time and accessed via the {@link #getException()} method is
  • 026 * now known as the <i>cause</i>, and may be accessed via the {@link
  • 027 * Throwable#getCause()} method, as well as the aforementioned "legacy method."
  • 028 *
  • 029 * @author unascribed
  • 030 * @version 1.21, 11/17/05
  • 031 * @see java.lang.Class#forName(java.lang.String)
  • 032 * @see java.lang.ClassLoader#findSystemClass(java.lang.String)
  • 033 * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  • 034 * @since JDK1.0
  • 035 */
  • 036public class ClassNotFoundException extends Exception {
  • 037 /**
  • 038 * use serialVersionUID from JDK 1.1.X for interoperability
  • 039 */
  • 040 private static final long serialVersionUID = 9176873029745254542L;
  • 041
  • 042 /**
  • 043 * This field holds the exception ex if the
  • 044 * ClassNotFoundException(String s, Throwable ex) constructor was
  • 045 * used to instantiate the object
  • 046 * @serial
  • 047 * @since 1.2
  • 048 */
  • 049 private Throwable ex;
  • 050
  • 051 /**
  • 052 * Constructs a <code>ClassNotFoundException</code> with no detail message.
  • 053 */
  • 054 public ClassNotFoundException() {
  • 055 super((Throwable)null); // Disallow initCause
  • 056 }
  • 057
  • 058 /**
  • 059 * Constructs a <code>ClassNotFoundException</code> with the
  • 060 * specified detail message.
  • 061 *
  • 062 * @param s the detail message.
  • 063 */
  • 064 public ClassNotFoundException(String s) {
  • 065 super(s, null); // Disallow initCause
  • 066 }
  • 067
  • 068 /**
  • 069 * Constructs a <code>ClassNotFoundException</code> with the
  • 070 * specified detail message and optional exception that was
  • 071 * raised while loading the class.
  • 072 *
  • 073 * @param s the detail message
  • 074 * @param ex the exception that was raised while loading the class
  • 075 * @since 1.2
  • 076 */
  • 077 public ClassNotFoundException(String s, Throwable ex) {
  • 078 super(s, null); // Disallow initCause
  • 079 this.ex = ex;
  • 080 }
  • 081
  • 082 /**
  • 083 * Returns the exception that was raised if an error occurred while
  • 084 * attempting to load the class. Otherwise, returns <tt>null</tt>.
  • 085 *
  • 086 * <p>This method predates the general-purpose exception chaining facility.
  • 087 * The {@link Throwable#getCause()} method is now the preferred means of
  • 088 * obtaining this information.
  • 089 *
  • 090 * @return the <code>Exception</code> that was raised while loading a class
  • 091 * @since 1.2
  • 092 */
  • 093 public Throwable getException() {
  • 094 return ex;
  • 095 }
  • 096
  • 097 /**
  • 098 * Returns the cause of this exception (the exception that was raised
  • 099 * 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 getCause() {
  • 106 return ex;
  • 107 }
  • 108}

文件:ClassNotFoundException.java
包名:java.lang
类名:ClassNotFoundException
继承:Exception
接口: