/[classpath]/classpath/java/lang/ClassNotFoundException.java
ViewVC logotype

Diff of /classpath/java/lang/ClassNotFoundException.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.7 by ericb, Sun Feb 24 04:25:16 2002 UTC
# Line 1  Line 1 
1  /* ClassNotFoundException.java -- exception thrown when attempting to load  /* ClassNotFoundException.java -- thrown when class definition cannot be found
2     a class when no definition for the class can be found.     Copyright (C) 1998, 2002 Free Software Foundation, Inc.
    Copyright (C) 1998 Free Software Foundation, Inc.  
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 8  GNU Classpath is free software; you can Line 7  GNU Classpath is free software; you can
7  it under the terms of the GNU General Public License as published by  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)  the Free Software Foundation; either version 2, or (at your option)
9  any later version.  any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but  GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Line 39  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package java.lang;  package java.lang;
40    
 import java.io.ObjectOutputStream;  
 import java.io.ObjectInputStream;  
 import java.io.IOException;  
 import java.io.PrintStream;  
 import java.io.PrintWriter;  
   
41  /**  /**
42   * Exceptions may be thrown by one part of a Java program and caught   * Thrown when a class is requested by reflection, but the class definition
43   * by another in order to deal with exceptional conditions.  This   * cannot be found. This exception is often chained from another Throwable.
  * exception can by thrown by specific methods of <code>ClassLoader</code>  
  * and <code>Class</code> when attempting to load a class when no definition  
  * for the specified class can be found.  
44   *   *
  * @since JDK 1.0  
  *  
45   * @author Brian Jones   * @author Brian Jones
46     * @author Eric Blake <ebb9@email.byu.edu>
47     * @see Class#forName(String)
48     * @see ClassLoader#findSystemClass(String)
49     * @see ClassLoader#loadClass(String, boolean)
50     * @status updated to 1.4
51   */   */
52  public class ClassNotFoundException extends Exception  public class ClassNotFoundException extends Exception
53  {  {
54    static final long serialVersionUID = 9176873029745254542L;    /**
55       * Compatible with JDK 1.0+.
56       */
57      private static final long serialVersionUID = 9176873029745254542L;
58    
   private Throwable ex = null;  
     
59    /**    /**
60     * Create an exception without a message.     * The cause of this exception (duplicates the one stored in Throwable).
61       *
62       * @serial the exception cause
63       * @since 1.2
64       */
65      private final Throwable ex;
66    
67      /**
68       * Create an exception without a message. Note that this initializes the
69       * cause to null.
70     */     */
71    public ClassNotFoundException()    public ClassNotFoundException()
72      {    {
73        super();      this(null, null);
74      }    }
75    
76    /**    /**
77     * Create an exception with a message.     * Create an exception with a message. Note that this initializes the
78       * cause to null.
79       *
80       * @param s the message
81     */     */
82    public ClassNotFoundException(String s)    public ClassNotFoundException(String s)
83      {    {
84        super(s);      this(s, null);
85      }    }
86    
87    /**    /**
88     * Create an exception with a message and include the exception     * Create an exception with a message and chain it to the exception
89     * which occurred while loading the class.     * which occurred while loading the class.
90     *     *
91     * @param ex the exception which occurred while loading the class     * @param s the message
92     *     * @param ex the chained exception
93     * @since JDK 1.2     * @since 1.2
94     */     */
95    public ClassNotFoundException(String s, Throwable ex)    public ClassNotFoundException(String s, Throwable ex)
96      {    {
97        super(s);      super(s, ex);
98        this.ex = ex;      this.ex = ex;
99      }    }
100    
101    /**    /**
102     * Returns the exception which occurred while loading the class,     * Returns the exception which occurred while loading the class,
103     * otherwise returns null.     * otherwise returns null. This is a legacy method; the preferred choice
104     *     * now is {@link Throwable#getCause()}.
105     * @since JDK 1.2     *
106       * @return the cause of this exception
107       * @since 1.2
108     */     */
109    public Throwable getException()    public Throwable getException()
110      {    {
111        return ex;      return ex;
112      }    }
113    
114    /**    /**
115     * Print a stack trace of the exception that occurred.     * Returns the exception which occurred while loading the class,
116     */     * otherwise returns null.
117    public void printStackTrace()     *
118      {     * @return the cause of this exception
119        if (ex == null)     * @since 1.4
120          {     */
121            super.printStackTrace();    public Throwable getCause()
122          }    {
123        else      return ex;
124          {    }
           ex.printStackTrace();  
         }  
     }  
   
   /**  
    * Print a stack trace of the exception that occurred to  
    * the specified <code>PrintStream</code>.  
    */  
   public void printStackTrace(PrintStream ps)  
     {  
       if (ex == null)  
         {  
           super.printStackTrace(ps);  
         }  
       else  
         {  
           ex.printStackTrace(ps);  
         }  
     }  
   
   /**  
    * Print a stack trace of the exception that occurred to  
    * the specified <code>PrintWriter</code>.  
    */  
   public void printStackTrace(PrintWriter pw)  
     {  
       if (ex == null)  
         {  
           super.printStackTrace(pw);  
         }  
       else  
         {  
           ex.printStackTrace(pw);  
         }  
     }  
   
   /**  
    * Serialize the object in a manner binary compatible with the JDK 1.2  
    */  
   private void writeObject(java.io.ObjectOutputStream s)  
     throws IOException  
     {  
       ObjectOutputStream.PutField oFields;  
       oFields = s.putFields();  
       oFields.put("ex", this.ex);  
       s.writeFields();  
     }  
   
   /**  
    * Deserialize the object in a manner binary compatible with the JDK 1.2  
    */      
   private void readObject(java.io.ObjectInputStream s)  
     throws IOException, ClassNotFoundException  
     {  
       ObjectInputStream.GetField oFields;  
       oFields = s.readFields();  
       ex = (Throwable)oFields.get("ex", (Throwable)null);  
     }  
125  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26