UndeclaredThrowableException.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* UndeclaredThrowableException.java -- wraps an undeclared checked exception
  2. thrown by a Proxy invocation handler
  3. Copyright (C) 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.reflect;
  33. /**
  34. * This exception class is thrown by a {@link Proxy} instance if
  35. * the {@link InvocationHandler#invoke(Object, Method, Object[]) invoke}
  36. * method of that instance's InvocationHandler attempts to throw an
  37. * exception that not declared by the throws clauses of all of the
  38. * interface methods that the proxy instance is implementing.
  39. *
  40. * <p>When thrown by Proxy, this class will always wrap a checked
  41. * exception, never {@link Error} or {@link RuntimeException},
  42. * which are unchecked.
  43. *
  44. * @author Eric Blake (ebb9@email.byu.edu)
  45. * @see Proxy
  46. * @see InvocationHandler
  47. * @since 1.3
  48. * @status updated to 1.4
  49. */
  50. public class UndeclaredThrowableException extends RuntimeException
  51. {
  52. /**
  53. * Compatible with JDK 1.3+.
  54. */
  55. private static final long serialVersionUID = 330127114055056639L;
  56. /**
  57. * The immutable exception that this wraps. This field is redundant
  58. * with {@link Throwable#getCause()}, but is necessary for serial compatibility.
  59. *
  60. * @serial the chained exception
  61. */
  62. private final Throwable undeclaredThrowable;
  63. /**
  64. * Wraps the given checked exception into a RuntimeException, with no
  65. * detail message. {@link Throwable#initCause(Throwable)} will fail
  66. * on this instance.
  67. *
  68. * @param cause the undeclared throwable that caused this exception,
  69. * may be null
  70. */
  71. public UndeclaredThrowableException(Throwable cause)
  72. {
  73. this(cause, null);
  74. }
  75. /**
  76. * Wraps the given checked exception into a RuntimeException, with the
  77. * specified detail message. {@link Throwable#initCause(Throwable)} will
  78. * fail on this instance.
  79. *
  80. * @param cause the undeclared throwable that caused this exception,
  81. * may be null
  82. * @param message the message, may be null
  83. */
  84. public UndeclaredThrowableException(Throwable cause, String message)
  85. {
  86. super(message, cause);
  87. undeclaredThrowable = cause;
  88. }
  89. /**
  90. * Returns the cause of this exception. If this exception was created
  91. * by a {@link Proxy} instance, it will be a non-null checked
  92. * exception. This method pre-dates exception chaining, and is now
  93. * simply a longer way to call <code>getCause()</code>.
  94. *
  95. * @return the cause of this exception, may be null
  96. * @see #getCause()
  97. */
  98. public Throwable getUndeclaredThrowable()
  99. {
  100. return undeclaredThrowable;
  101. }
  102. /**
  103. * Returns the cause of this exception. If this exception was created
  104. * by a {@link Proxy} instance, it will be a non-null checked
  105. * exception.
  106. *
  107. * @return the cause of this exception, may be null
  108. * @since 1.4
  109. */
  110. public Throwable getCause()
  111. {
  112. return undeclaredThrowable;
  113. }
  114. }