KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > rmi > RemoteException


1 /*
2  * @(#)RemoteException.java 1.24 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.rmi;
9
10 /**
11  * A <code>RemoteException</code> is the common superclass for a number of
12  * communication-related exceptions that may occur during the execution of a
13  * remote method call. Each method of a remote interface, an interface that
14  * extends <code>java.rmi.Remote</code>, must list
15  * <code>RemoteException</code> in its throws clause.
16  *
17  * <p>As of release 1.4, this exception has been retrofitted to conform to
18  * the general purpose exception-chaining mechanism. The "wrapped remote
19  * exception" that may be provided at construction time and accessed via
20  * the public {@link #detail} field is now known as the <i>cause</i>, and
21  * may be accessed via the {@link Throwable#getCause()} method, as well as
22  * the aforementioned "legacy field."
23  *
24  * <p>Invoking the method {@link Throwable#initCause(Throwable)} on an
25  * instance of <code>RemoteException</code> always throws {@link
26  * IllegalStateException}.
27  *
28  * @version 1.24, 12/19/03
29  * @author Ann Wollrath
30  * @since JDK1.1
31  */

32 public class RemoteException extends java.io.IOException JavaDoc {
33
34     /* indicate compatibility with JDK 1.1.x version of class */
35     private static final long serialVersionUID = -5148567311918794206L;
36
37     /**
38      * The cause of the remote exception.
39      *
40      * <p>This field predates the general-purpose exception chaining facility.
41      * The {@link Throwable#getCause()} method is now the preferred means of
42      * obtaining this information.
43      *
44      * @serial
45      */

46     public Throwable JavaDoc detail;
47
48     /**
49      * Constructs a <code>RemoteException</code>.
50      */

51     public RemoteException() {
52         initCause(null); // Disallow subsequent initCause
53
}
54
55     /**
56      * Constructs a <code>RemoteException</code> with the specified
57      * detail message.
58      *
59      * @param s the detail message
60      */

61     public RemoteException(String JavaDoc s) {
62     super(s);
63         initCause(null); // Disallow subsequent initCause
64
}
65
66     /**
67      * Constructs a <code>RemoteException</code> with the specified detail
68      * message and cause. This constructor sets the {@link #detail}
69      * field to the specified <code>Throwable</code>.
70      *
71      * @param s the detail message
72      * @param cause the cause
73      */

74     public RemoteException(String JavaDoc s, Throwable JavaDoc cause) {
75     super(s);
76         initCause(null); // Disallow subsequent initCause
77
detail = cause;
78     }
79
80     /**
81      * Returns the detail message, including the message from the cause, if
82      * any, of this exception.
83      *
84      * @return the detail message
85      */

86     public String JavaDoc getMessage() {
87     if (detail == null) {
88         return super.getMessage();
89     } else {
90         return super.getMessage() + "; nested exception is: \n\t" +
91         detail.toString();
92     }
93     }
94
95     /**
96      * Returns the cause of this exception. This method returns the value
97      * of the {@link #detail} field.
98      *
99      * @return the cause, which may be <tt>null</tt>.
100      * @since 1.4
101      */

102     public Throwable JavaDoc getCause() {
103         return detail;
104     }
105 }
106
Popular Tags