ExceptionInInitializerError.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ExceptionInInitializerError.java -- thrown when class initialization fails
  2. with an uncaught exception
  3. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package java.lang;
  33. /**
  34. * An <code>ExceptionInInitializerError</code> is thrown when an uncaught
  35. * exception has occurred in a static initializer or the initializer for a
  36. * static variable. In general, this wraps only RuntimeExceptions, since the
  37. * compiler does not allow a checked exception to be uncaught in an
  38. * initializer. This exception only occurs during reflection, when a class
  39. * is initialized as part of another action.
  40. *
  41. * @author Brian Jones
  42. * @author Tom Tromey (tromey@cygnus.com)
  43. * @author Eric Blake (ebb9@email.byu.edu)
  44. * @since 1.1
  45. * @status updated to 1.4
  46. */
  47. public class ExceptionInInitializerError extends LinkageError
  48. {
  49. /**
  50. * Compatible with JDK 1.1+.
  51. */
  52. static final long serialVersionUID = 1521711792217232256L;
  53. /**
  54. * The cause of this exception (duplicates the one stored in Throwable).
  55. *
  56. * @serial the exception cause
  57. */
  58. private final Throwable exception;
  59. /**
  60. * Create an error without a message. The cause is initialized as null.
  61. */
  62. public ExceptionInInitializerError()
  63. {
  64. this((String) null);
  65. }
  66. /**
  67. * Create an error with a message. The cause is initialized as null.
  68. *
  69. * @param s the message
  70. */
  71. public ExceptionInInitializerError(String s)
  72. {
  73. super(s);
  74. exception = null;
  75. }
  76. /**
  77. * Creates an error an saves a reference to the <code>Throwable</code>
  78. * object. The message string is null.
  79. *
  80. * @param t the exception thrown
  81. */
  82. public ExceptionInInitializerError(Throwable t)
  83. {
  84. super(null);
  85. initCause(t);
  86. exception = t;
  87. }
  88. /**
  89. * Return the exception that caused this error to be created. This is a
  90. * legacy method; the preferred choice now is {@link Throwable#getCause()}.
  91. *
  92. * @return the cause, or null if unknown
  93. */
  94. public Throwable getException()
  95. {
  96. return exception;
  97. }
  98. /**
  99. * Return the exception that cause this error to be created.
  100. *
  101. * @return the cause, or null if unknown
  102. * @since 1.4
  103. */
  104. public Throwable getCause()
  105. {
  106. return exception;
  107. }
  108. }