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

Diff of /classpath/java/lang/ExceptionInInitializerError.java

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

revision 1.7 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.8 by ericb, Sun Feb 24 04:25:16 2002 UTC
# Line 1  Line 1 
1  /* ExceptionInInitializerError.java  /* ExceptionInInitializerError.java -- thrown when class initialization fails
2     Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.     with an uncaught exception
3       Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
6    
# Line 7  GNU Classpath is free software; you can Line 8  GNU Classpath is free software; you can
8  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
9  the Free Software Foundation; either version 2, or (at your option)  the Free Software Foundation; either version 2, or (at your option)
10  any later version.  any later version.
11    
12  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
13  WITHOUT ANY WARRANTY; without even the implied warranty of  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Line 38  exception statement from your version. * Line 39  exception statement from your version. *
39    
40  package java.lang;  package java.lang;
41    
 import java.io.PrintStream;  
 import java.io.PrintWriter;  
   
 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3  
  * "The Java Language Specification", ISBN 0-201-63451-1  
  * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.  
  * Status:  Believed complete and correct.  
  */  
   
42  /**  /**
43   * An <code>ExceptionInInitializerError</code> is thrown when an   * An <code>ExceptionInInitializerError</code> is thrown when an uncaught
44   * unexpected exception has occurred in a static initializer or the   * exception has occurred in a static initializer or the initializer for a
45   * initializer for a static variable.   * static variable. In general, this wraps only RuntimeExceptions, since the
46     * compiler does not allow a checked exception to be uncaught in an
47     * initializer. This exception only occurs during reflection, when a class
48     * is initialized as part of another action.
49   *   *
  * @since JDK 1.1  
  *  
50   * @author Brian Jones   * @author Brian Jones
51   * @author Tom Tromey <tromey@cygnus.com>   * @author Tom Tromey <tromey@cygnus.com>
52   * @date October 1, 1998   * @author Eric Blake <ebb9@email.byu.edu>
53     * @since 1.1
54     * @status updated to 1.4
55   */   */
56  public class ExceptionInInitializerError extends LinkageError  public class ExceptionInInitializerError extends LinkageError
57  {  {
58      /**
59       * Compatible with JDK 1.1+.
60       */
61    static final long serialVersionUID = 1521711792217232256L;    static final long serialVersionUID = 1521711792217232256L;
62    
63    private Throwable exception = null;    /**
64       * The cause of this exception (duplicates the one stored in Throwable).
65       *
66       * @serial the exception cause
67       */
68      private final Throwable exception;
69    
70    /**    /**
71     * Create an error without a message.     * Create an error without a message. The cause is initialized as null.
72     */     */
73    public ExceptionInInitializerError()    public ExceptionInInitializerError()
74      {    {
75        super();      this((String) null);
76      }    }
77    
78    /**    /**
79     * Create an error with a message.     * Create an error with a message. The cause is initialized as null.
80       *
81       * @param s the message
82     */     */
83    public ExceptionInInitializerError(String s)    public ExceptionInInitializerError(String s)
84      {    {
85        super(s);      super(s);
86      }      exception = null;
87      }
88    
89    /**    /**
90     * Creates an error an saves a reference to the <code>Throwable</code>     * Creates an error an saves a reference to the <code>Throwable</code>
91     * object.     * object. The message string is null.
92     *     *
93     * @param t the exception thrown     * @param t the exception thrown
94     */     */
95    public ExceptionInInitializerError(Throwable t)    public ExceptionInInitializerError(Throwable t)
96      {    {
97        super(t.toString());      super(null);
98        exception = t;      initCause(t);
99      }      exception = t;
100      }
101    /**  
102     * Return the exception that caused this error to be created.    /**
103     * @return the stored <code>Throwable</code> object or <code>null</code>     * Return the exception that caused this error to be created. This is a
104     * if this <code>ExceptionInInitializerError</code> has no stored     * legacy method; the preferred choice now is {@link Throwable#getCause()}.
105     * <code>Throwable</code> object.     *
106       * @return the cause, or null if unknown
107     */     */
108    public Throwable getException()    public Throwable getException()
109      {    {
110        return exception;      return exception;
111      }    }
112    
113    /**    /**
114     * Print a stack trace of the exception that occurred.     * Return the exception that cause this error to be created.
115     */     *
116    public void printStackTrace()     * @return the cause, or null if unknown
117      {     * @since 1.4
118        if (exception == null)     */
119          {    public Throwable getCause()
120            super.printStackTrace();    {
121          }      return exception;
122        else    }
         {  
           System.err.print(this.getClass() + ": ");  
           exception.printStackTrace();  
         }  
     }  
   
   /**  
    * Print a stack trace of the exception that occurred to  
    * the specified <code>PrintStream</code>.  
    */  
   public void printStackTrace(PrintStream ps)  
     {  
       if (exception == null)  
         {  
           super.printStackTrace(ps);  
         }  
       else  
         {  
           ps.print(this.getClass() + ": ");  
           exception.printStackTrace(ps);  
         }  
     }  
   
   /**  
    * Print a stack trace of the exception that occurred to  
    * the specified <code>PrintWriter</code>.  
    */  
   public void printStackTrace(PrintWriter pw)  
     {  
       if (exception == null)  
         {  
           super.printStackTrace(pw);  
         }  
       else  
         {  
           pw.print(this.getClass() + ": ");  
           exception.printStackTrace(pw);  
         }  
     }  
123  }  }

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

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