Path: blob/master/src/java.rmi/share/classes/java/rmi/RemoteException.java
41152 views
/*1* Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.rmi;2627/**28* A {@code RemoteException} is the common superclass for a number of29* communication-related exceptions that may occur during the execution of a30* remote method call. Each method of a remote interface, an interface that31* extends {@code java.rmi.Remote}, must list32* {@code RemoteException} in its throws clause.33*34* <p>As of release 1.4, this exception has been retrofitted to conform to35* the general purpose exception-chaining mechanism. The "wrapped remote36* exception" that may be provided at construction time and accessed via37* the public {@link #detail} field is now known as the <i>cause</i>, and38* may be accessed via the {@link Throwable#getCause()} method, as well as39* the aforementioned "legacy field."40*41* <p>Invoking the method {@link Throwable#initCause(Throwable)} on an42* instance of {@code RemoteException} always throws {@link43* IllegalStateException}.44*45* @author Ann Wollrath46* @since 1.147*/48public class RemoteException extends java.io.IOException {4950/* indicate compatibility with JDK 1.1.x version of class */51private static final long serialVersionUID = -5148567311918794206L;5253/**54* The cause of the remote exception.55*56* <p>This field predates the general-purpose exception chaining facility.57* The {@link Throwable#getCause()} method is now the preferred means of58* obtaining this information.59*60* @serial61*/62public Throwable detail;6364/**65* Constructs a {@code RemoteException}.66*/67public RemoteException() {68initCause(null); // Disallow subsequent initCause69}7071/**72* Constructs a {@code RemoteException} with the specified73* detail message.74*75* @param s the detail message76*/77public RemoteException(String s) {78super(s);79initCause(null); // Disallow subsequent initCause80}8182/**83* Constructs a {@code RemoteException} with the specified detail84* message and cause. This constructor sets the {@link #detail}85* field to the specified {@code Throwable}.86*87* @param s the detail message88* @param cause the cause89*/90public RemoteException(String s, Throwable cause) {91super(s);92initCause(null); // Disallow subsequent initCause93detail = cause;94}9596/**97* Returns the detail message, including the message from the cause, if98* any, of this exception.99*100* @return the detail message101*/102public String getMessage() {103if (detail == null) {104return super.getMessage();105} else {106return super.getMessage() + "; nested exception is: \n\t" +107detail.toString();108}109}110111/**112* Returns the cause of this exception. This method returns the value113* of the {@link #detail} field.114*115* @return the cause, which may be {@code null}.116* @since 1.4117*/118public Throwable getCause() {119return detail;120}121}122123124