001/* InvocationTargetException.java -- Wrapper exception for reflection 002 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.lang.reflect; 040 041/** 042 * InvocationTargetException is sort of a way to "wrap" whatever exception 043 * comes up when a method or constructor is called via Reflection. As of 044 * JDK 1.4, it was retrofitted to match the exception chaining of all other 045 * exceptions, but <code>getTargetException()</code> still works. 046 * 047 * @author John Keiser 048 * @author Tom Tromey (tromey@cygnus.com) 049 * @author Eric Blake (ebb9@email.byu.edu) 050 * @see Method#invoke(Object,Object[]) 051 * @see Constructor#newInstance(Object[]) 052 * @since 1.1 053 * @status updated to 1.7 054 */ 055public class InvocationTargetException extends ReflectiveOperationException 056{ 057 /** 058 * Compatible with JDK 1.1+. 059 */ 060 private static final long serialVersionUID = 4085088731926701167L; 061 062 /** 063 * The chained exception. This field is only around for serial compatibility. 064 * 065 * @serial the chained exception 066 */ 067 private final Throwable target; 068 069 /** 070 * Construct an exception with null as the cause. The cause is initialized 071 * to null. 072 */ 073 protected InvocationTargetException() 074 { 075 this(null, null); 076 } 077 078 /** 079 * Create an <code>InvocationTargetException</code> using another 080 * exception. 081 * 082 * @param targetException the exception to wrap 083 */ 084 public InvocationTargetException(Throwable targetException) 085 { 086 this(targetException, null); 087 } 088 089 /** 090 * Create an <code>InvocationTargetException</code> using another 091 * exception and an error message. 092 * 093 * @param targetException the exception to wrap 094 * @param err an extra reason for the exception-throwing 095 */ 096 public InvocationTargetException(Throwable targetException, String err) 097 { 098 super(err, targetException); 099 target = targetException; 100 } 101 102 /** 103 * Get the wrapped (targeted) exception. 104 * 105 * @return the targeted exception 106 * @see #getCause() 107 */ 108 public Throwable getTargetException() 109 { 110 return target; 111 } 112 113 /** 114 * Returns the cause of this exception (which may be null). 115 * 116 * @return the cause 117 * @since 1.4 118 */ 119 public Throwable getCause() 120 { 121 return target; 122 } 123}