001/* UndeclaredThrowableException.java -- wraps an undeclared checked exception 002 thrown by a Proxy invocation handler 003 Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. 004 005This file is part of GNU Classpath. 006 007GNU Classpath is free software; you can redistribute it and/or modify 008it under the terms of the GNU General Public License as published by 009the Free Software Foundation; either version 2, or (at your option) 010any later version. 011 012GNU Classpath is distributed in the hope that it will be useful, but 013WITHOUT ANY WARRANTY; without even the implied warranty of 014MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015General Public License for more details. 016 017You should have received a copy of the GNU General Public License 018along with GNU Classpath; see the file COPYING. If not, write to the 019Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02002110-1301 USA. 021 022Linking this library statically or dynamically with other modules is 023making a combined work based on this library. Thus, the terms and 024conditions of the GNU General Public License cover the whole 025combination. 026 027As a special exception, the copyright holders of this library give you 028permission to link this library with independent modules to produce an 029executable, regardless of the license terms of these independent 030modules, and to copy and distribute the resulting executable under 031terms of your choice, provided that you also meet, for each linked 032independent module, the terms and conditions of the license of that 033module. An independent module is a module which is not derived from 034or based on this library. If you modify this library, you may extend 035this exception to your version of the library, but you are not 036obligated to do so. If you do not wish to do so, delete this 037exception statement from your version. */ 038 039 040package java.lang.reflect; 041 042/** 043 * This exception class is thrown by a {@link Proxy} instance if 044 * the {@link InvocationHandler#invoke(Object, Method, Object[]) invoke} 045 * method of that instance's InvocationHandler attempts to throw an 046 * exception that not declared by the throws clauses of all of the 047 * interface methods that the proxy instance is implementing. 048 * 049 * <p>When thrown by Proxy, this class will always wrap a checked 050 * exception, never {@link Error} or {@link RuntimeException}, 051 * which are unchecked. 052 * 053 * @author Eric Blake (ebb9@email.byu.edu) 054 * @see Proxy 055 * @see InvocationHandler 056 * @since 1.3 057 * @status updated to 1.4 058 */ 059public class UndeclaredThrowableException extends RuntimeException 060{ 061 /** 062 * Compatible with JDK 1.3+. 063 */ 064 private static final long serialVersionUID = 330127114055056639L; 065 066 /** 067 * The immutable exception that this wraps. This field is redundant 068 * with {@link Throwable#getCause()}, but is necessary for serial compatibility. 069 * 070 * @serial the chained exception 071 */ 072 private final Throwable undeclaredThrowable; 073 074 /** 075 * Wraps the given checked exception into a RuntimeException, with no 076 * detail message. {@link Throwable#initCause(Throwable)} will fail 077 * on this instance. 078 * 079 * @param cause the undeclared throwable that caused this exception, 080 * may be null 081 */ 082 public UndeclaredThrowableException(Throwable cause) 083 { 084 this(cause, null); 085 } 086 087 /** 088 * Wraps the given checked exception into a RuntimeException, with the 089 * specified detail message. {@link Throwable#initCause(Throwable)} will 090 * fail on this instance. 091 * 092 * @param cause the undeclared throwable that caused this exception, 093 * may be null 094 * @param message the message, may be null 095 */ 096 public UndeclaredThrowableException(Throwable cause, String message) 097 { 098 super(message, cause); 099 undeclaredThrowable = cause; 100 } 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. This method pre-dates exception chaining, and is now 106 * simply a longer way to call <code>getCause()</code>. 107 * 108 * @return the cause of this exception, may be null 109 * @see #getCause() 110 */ 111 public Throwable getUndeclaredThrowable() 112 { 113 return undeclaredThrowable; 114 } 115 116 /** 117 * Returns the cause of this exception. If this exception was created 118 * by a {@link Proxy} instance, it will be a non-null checked 119 * exception. 120 * 121 * @return the cause of this exception, may be null 122 * @since 1.4 123 */ 124 public Throwable getCause() 125 { 126 return undeclaredThrowable; 127 } 128}