001/* RemoteException.java -- common superclass for exceptions in java.rmi 002 Copyright (c) 1996, 1997, 1998, 1999, 2002, 2006 003 Free Software Foundation, Inc. 004 005This file is part of GNU Classpath. 006 007GNU Classpath is free software; you can redistribute it and/or modify 008it under the terms of the GNU General Public License as published by 009the Free Software Foundation; either version 2, or (at your option) 010any later version. 011 012GNU Classpath is distributed in the hope that it will be useful, but 013WITHOUT ANY WARRANTY; without even the implied warranty of 014MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015General Public License for more details. 016 017You should have received a copy of the GNU General Public License 018along with GNU Classpath; see the file COPYING. If not, write to the 019Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02002110-1301 USA. 021 022Linking this library statically or dynamically with other modules is 023making a combined work based on this library. Thus, the terms and 024conditions of the GNU General Public License cover the whole 025combination. 026 027As a special exception, the copyright holders of this library give you 028permission to link this library with independent modules to produce an 029executable, regardless of the license terms of these independent 030modules, and to copy and distribute the resulting executable under 031terms of your choice, provided that you also meet, for each linked 032independent module, the terms and conditions of the license of that 033module. An independent module is a module which is not derived from 034or based on this library. If you modify this library, you may extend 035this exception to your version of the library, but you are not 036obligated to do so. If you do not wish to do so, delete this 037exception statement from your version. */ 038 039package java.rmi; 040 041import java.io.IOException; 042 043/** 044 * The superclass of exceptions related to RMI (remote method invocation). 045 * Classes that implement <code>java.rmi.Remote</code> should list this 046 * exception in their throws clause. 047 * 048 * @author unknown 049 * @since 1.1 050 * @status updated to 1.4 051 */ 052public class RemoteException extends IOException 053{ 054 /** 055 * Compatible with JDK 1.2+. 056 */ 057 private static final long serialVersionUID = -5148567311918794206l; 058 059 /** 060 * The cause of this exception. This pre-dates the exception chaining 061 * of Throwable; and although you can change this field, you are wiser 062 * to leave it alone. 063 * 064 * @serial the exception cause 065 */ 066 public Throwable detail; 067 068 /** 069 * Create an exception with no message, and cause initialized to null. 070 */ 071 public RemoteException() 072 { 073 this(null, null); 074 } 075 076 /** 077 * Create an exception with the given message, and cause initialized to null. 078 * 079 * @param s the message 080 */ 081 public RemoteException(String s) 082 { 083 this(s, null); 084 } 085 086 /** 087 * Create an exception with the given message and cause. 088 * 089 * @param s the message 090 * @param e the cause 091 */ 092 public RemoteException(String s, Throwable e) 093 { 094 super(s); 095 initCause(e); 096 detail = e; 097 } 098 099 /** 100 * This method returns a message indicating what went wrong, in this 101 * format: 102 * <code>super.getMessage() + (detail == null ? "" 103 * : "; nested exception is:\n\t" + detail)</code>. 104 * 105 * @return the chained message 106 */ 107 public String getMessage() 108 { 109 if (detail == this || detail == null) 110 return super.getMessage(); 111 return super.getMessage() + "; nested exception is:\n\t" + detail; 112 } 113 114 /** 115 * Returns the cause of this exception. Note that this may not be the 116 * original cause, thanks to the <code>detail</code> field being public 117 * and non-final (yuck). However, to avoid violating the contract of 118 * Throwable.getCause(), this returns null if <code>detail == this</code>, 119 * as no exception can be its own cause. 120 * 121 * @return the cause 122 * @since 1.4 123 */ 124 public Throwable getCause() 125 { 126 return detail == this ? null : detail; 127 } 128}