Commit 8f7dfb53 by Nathanael Nerode Committed by Tom Tromey

ClassNotFoundException.java: New Classpath version.

2002-06-17  Nathanael Nerode  <neroden@twcny.rr.com>

	* java/lang/ClassNotFoundException.java: New Classpath version.

From-SVN: r54713
parent 7f11f1f9
2002-06-17 Nathanael Nerode <neroden@twcny.rr.com> 2002-06-17 Nathanael Nerode <neroden@twcny.rr.com>
* java/lang/ClassNotFoundException.java: New Classpath version.
2002-06-17 Nathanael Nerode <neroden@twcny.rr.com>
* java/rmi/activation/ActivateFailedException.java: Remerge from * java/rmi/activation/ActivateFailedException.java: Remerge from
Classpath version. Classpath version.
* java/rmi/activation/ActivationException.java: Ditto. * java/rmi/activation/ActivationException.java: Ditto.
......
/* ClassNotFoundException.java -- exception thrown when attempting to load /* ClassNotFoundException.java -- thrown when class definition cannot be found
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.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -39,64 +38,73 @@ exception statement from your version. */ ...@@ -39,64 +38,73 @@ exception statement from your version. */
package java.lang; package java.lang;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
/** /**
* 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
* 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.
*
* @since JDK 1.0
* *
* @author Brian Jones * @author Brian Jones
* @author Eric Blake <ebb9@email.byu.edu>
* @see Class#forName(String)
* @see ClassLoader#findSystemClass(String)
* @see ClassLoader#loadClass(String, boolean)
* @status updated to 1.4
*/ */
public class ClassNotFoundException extends Exception public class ClassNotFoundException extends Exception
{ {
static final long serialVersionUID = 9176873029745254542L; /**
* Compatible with JDK 1.0+.
*/
private static final long serialVersionUID = 9176873029745254542L;
private Throwable ex = null; /**
* The cause of this exception (duplicates the one stored in Throwable).
*
* @serial the exception cause
* @since 1.2
*/
private final Throwable ex;
/** /**
* Create an exception without a message. * Create an exception without a message. Note that this initializes the
* cause to null.
*/ */
public ClassNotFoundException() public ClassNotFoundException()
{ {
super(); this(null, null);
} }
/** /**
* Create an exception with a message. * Create an exception with a message. Note that this initializes the
* cause to null.
*
* @param s the message
*/ */
public ClassNotFoundException(String s) public ClassNotFoundException(String s)
{ {
super(s); this(s, null);
} }
/** /**
* Create an exception with a message and include the exception * Create an exception with a message and chain it to the exception
* which occurred while loading the class. * which occurred while loading the class.
* *
* @param ex the exception which occurred while loading the class * @param s the message
* * @param ex the chained exception
* @since JDK 1.2 * @since 1.2
*/ */
public ClassNotFoundException(String s, Throwable ex) public ClassNotFoundException(String s, Throwable ex)
{ {
super(s); super(s, ex);
this.ex = ex; this.ex = ex;
} }
/** /**
* Returns the exception which occurred while loading the class, * Returns the exception which occurred while loading the class,
* otherwise returns null. * otherwise returns null. This is a legacy method; the preferred choice
* now is {@link Throwable#getCause()}.
* *
* @since JDK 1.2 * @return the cause of this exception
* @since 1.2
*/ */
public Throwable getException() public Throwable getException()
{ {
...@@ -104,72 +112,14 @@ public class ClassNotFoundException extends Exception ...@@ -104,72 +112,14 @@ public class ClassNotFoundException extends Exception
} }
/** /**
* Print a stack trace of the exception that occurred. * Returns the exception which occurred while loading the class,
*/ * otherwise returns null.
public void printStackTrace() *
{ * @return the cause of this exception
if (ex == null) * @since 1.4
{
super.printStackTrace();
}
else
{
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) public Throwable getCause()
throws IOException, ClassNotFoundException
{ {
ObjectInputStream.GetField oFields; return ex;
oFields = s.readFields();
ex = (Throwable)oFields.get("ex", (Throwable)null);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment