1/*
2 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.rmi.activation;
27
28/**
29 * General exception used by the activation interfaces.
30 *
31 * <p>As of release 1.4, this exception has been retrofitted to conform to
32 * the general purpose exception-chaining mechanism.  The "detail exception"
33 * that may be provided at construction time and accessed via the public
34 * {@link #detail} field is now known as the <i>cause</i>, and may be
35 * accessed via the {@link Throwable#getCause()} method, as well as
36 * the aforementioned "legacy field."
37 *
38 * <p>Invoking the method {@link Throwable#initCause(Throwable)} on an
39 * instance of {@code ActivationException} always throws {@link
40 * IllegalStateException}.
41 *
42 * @author      Ann Wollrath
43 * @since       1.2
44 */
45public class ActivationException extends Exception {
46
47    /**
48     * The cause of the activation exception.
49     *
50     * <p>This field predates the general-purpose exception chaining facility.
51     * The {@link Throwable#getCause()} method is now the preferred means of
52     * obtaining this information.
53     *
54     * @serial
55     */
56    public Throwable detail;
57
58    /** indicate compatibility with the Java 2 SDK v1.2 version of class */
59    private static final long serialVersionUID = -4320118837291406071L;
60
61    /**
62     * Constructs an {@code ActivationException}.
63     */
64    public ActivationException() {
65        initCause(null);  // Disallow subsequent initCause
66    }
67
68    /**
69     * Constructs an {@code ActivationException} with the specified
70     * detail message.
71     *
72     * @param s the detail message
73     */
74    public ActivationException(String s) {
75        super(s);
76        initCause(null);  // Disallow subsequent initCause
77    }
78
79    /**
80     * Constructs an {@code ActivationException} with the specified
81     * detail message and cause.  This constructor sets the {@link #detail}
82     * field to the specified {@code Throwable}.
83     *
84     * @param s the detail message
85     * @param cause the cause
86     */
87    public ActivationException(String s, Throwable cause) {
88        super(s);
89        initCause(null);  // Disallow subsequent initCause
90        detail = cause;
91    }
92
93    /**
94     * Returns the detail message, including the message from the cause, if
95     * any, of this exception.
96     *
97     * @return  the detail message
98     */
99    public String getMessage() {
100        if (detail == null)
101            return super.getMessage();
102        else
103            return super.getMessage() +
104                "; nested exception is: \n\t" +
105                detail.toString();
106    }
107
108    /**
109     * Returns the cause of this exception.  This method returns the value
110     * of the {@link #detail} field.
111     *
112     * @return  the cause, which may be {@code null}.
113     * @since   1.4
114     */
115    public Throwable getCause() {
116        return detail;
117    }
118}
119