jtulach@258: /* jtulach@258: * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved. jtulach@258: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jtulach@258: * jtulach@258: * This code is free software; you can redistribute it and/or modify it jtulach@258: * under the terms of the GNU General Public License version 2 only, as jtulach@258: * published by the Free Software Foundation. Oracle designates this jtulach@258: * particular file as subject to the "Classpath" exception as provided jtulach@258: * by Oracle in the LICENSE file that accompanied this code. jtulach@258: * jtulach@258: * This code is distributed in the hope that it will be useful, but WITHOUT jtulach@258: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jtulach@258: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jtulach@258: * version 2 for more details (a copy is included in the LICENSE file that jtulach@258: * accompanied this code). jtulach@258: * jtulach@258: * You should have received a copy of the GNU General Public License version jtulach@258: * 2 along with this work; if not, write to the Free Software Foundation, jtulach@258: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jtulach@258: * jtulach@258: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jtulach@258: * or visit www.oracle.com if you need additional information or have any jtulach@258: * questions. jtulach@258: */ jtulach@258: jtulach@258: package java.lang.reflect; jtulach@258: jtulach@258: /** jtulach@258: * InvocationTargetException is a checked exception that wraps jtulach@258: * an exception thrown by an invoked method or constructor. jtulach@258: * jtulach@258: *

As of release 1.4, this exception has been retrofitted to conform to jtulach@258: * the general purpose exception-chaining mechanism. The "target exception" jtulach@258: * that is provided at construction time and accessed via the jtulach@258: * {@link #getTargetException()} method is now known as the cause, jtulach@258: * and may be accessed via the {@link Throwable#getCause()} method, jtulach@258: * as well as the aforementioned "legacy method." jtulach@258: * jtulach@258: * @see Method jtulach@258: * @see Constructor jtulach@258: */ jtulach@258: public class InvocationTargetException extends ReflectiveOperationException { jtulach@258: /** jtulach@258: * Use serialVersionUID from JDK 1.1.X for interoperability jtulach@258: */ jtulach@258: private static final long serialVersionUID = 4085088731926701167L; jtulach@258: jtulach@258: /** jtulach@258: * This field holds the target if the jtulach@258: * InvocationTargetException(Throwable target) constructor was jtulach@258: * used to instantiate the object jtulach@258: * jtulach@258: * @serial jtulach@258: * jtulach@258: */ jtulach@258: private Throwable target; jtulach@258: jtulach@258: /** jtulach@258: * Constructs an {@code InvocationTargetException} with jtulach@258: * {@code null} as the target exception. jtulach@258: */ jtulach@258: protected InvocationTargetException() { jtulach@258: super((Throwable)null); // Disallow initCause jtulach@258: } jtulach@258: jtulach@258: /** jtulach@258: * Constructs a InvocationTargetException with a target exception. jtulach@258: * jtulach@258: * @param target the target exception jtulach@258: */ jtulach@258: public InvocationTargetException(Throwable target) { jtulach@258: super((Throwable)null); // Disallow initCause jtulach@258: this.target = target; jtulach@258: } jtulach@258: jtulach@258: /** jtulach@258: * Constructs a InvocationTargetException with a target exception jtulach@258: * and a detail message. jtulach@258: * jtulach@258: * @param target the target exception jtulach@258: * @param s the detail message jtulach@258: */ jtulach@258: public InvocationTargetException(Throwable target, String s) { jtulach@258: super(s, null); // Disallow initCause jtulach@258: this.target = target; jtulach@258: } jtulach@258: jtulach@258: /** jtulach@258: * Get the thrown target exception. jtulach@258: * jtulach@258: *

This method predates the general-purpose exception chaining facility. jtulach@258: * The {@link Throwable#getCause()} method is now the preferred means of jtulach@258: * obtaining this information. jtulach@258: * jtulach@258: * @return the thrown target exception (cause of this exception). jtulach@258: */ jtulach@258: public Throwable getTargetException() { jtulach@258: return target; jtulach@258: } jtulach@258: jtulach@258: /** jtulach@258: * Returns the cause of this exception (the thrown target exception, jtulach@258: * which may be {@code null}). jtulach@258: * jtulach@258: * @return the cause of this exception. jtulach@258: * @since 1.4 jtulach@258: */ jtulach@258: public Throwable getCause() { jtulach@258: return target; jtulach@258: } jtulach@258: }