001 /* InvocationTargetException.java -- Wrapper exception for reflection 002 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package 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.4 054 */ 055 public class InvocationTargetException extends Exception 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 }