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. package java.rmi;
  8. /**
  9. * A <code>RemoteException</code> is the common superclass for a number of
  10. * communication-related exceptions that may occur during the execution of a
  11. * remote method call. Each method of a remote interface, an interface that
  12. * extends <code>java.rmi.Remote</code>, must list
  13. * <code>RemoteException</code> in its throws clause.
  14. *
  15. * <p>As of release 1.4, this exception has been retrofitted to conform to
  16. * the general purpose exception-chaining mechanism. The "wrapped remote
  17. * exception" that may be provided at construction time and accessed via
  18. * the public {@link #detail} field is now known as the <i>cause</i>, and
  19. * may be accessed via the {@link Throwable#getCause()} method, as well as
  20. * the aforementioned "legacy field."
  21. *
  22. * <p>Invoking the method {@link Throwable#initCause(Throwable)} on an
  23. * instance of <code>RemoteException</code> always throws {@link
  24. * IllegalStateException}.
  25. *
  26. * @version 1.24, 12/19/03
  27. * @author Ann Wollrath
  28. * @since JDK1.1
  29. */
  30. public class RemoteException extends java.io.IOException {
  31. /* indicate compatibility with JDK 1.1.x version of class */
  32. private static final long serialVersionUID = -5148567311918794206L;
  33. /**
  34. * The cause of the remote exception.
  35. *
  36. * <p>This field predates the general-purpose exception chaining facility.
  37. * The {@link Throwable#getCause()} method is now the preferred means of
  38. * obtaining this information.
  39. *
  40. * @serial
  41. */
  42. public Throwable detail;
  43. /**
  44. * Constructs a <code>RemoteException</code>.
  45. */
  46. public RemoteException() {
  47. initCause(null); // Disallow subsequent initCause
  48. }
  49. /**
  50. * Constructs a <code>RemoteException</code> with the specified
  51. * detail message.
  52. *
  53. * @param s the detail message
  54. */
  55. public RemoteException(String s) {
  56. super(s);
  57. initCause(null); // Disallow subsequent initCause
  58. }
  59. /**
  60. * Constructs a <code>RemoteException</code> with the specified detail
  61. * message and cause. This constructor sets the {@link #detail}
  62. * field to the specified <code>Throwable</code>.
  63. *
  64. * @param s the detail message
  65. * @param cause the cause
  66. */
  67. public RemoteException(String s, Throwable cause) {
  68. super(s);
  69. initCause(null); // Disallow subsequent initCause
  70. detail = cause;
  71. }
  72. /**
  73. * Returns the detail message, including the message from the cause, if
  74. * any, of this exception.
  75. *
  76. * @return the detail message
  77. */
  78. public String getMessage() {
  79. if (detail == null) {
  80. return super.getMessage();
  81. } else {
  82. return super.getMessage() + "; nested exception is: \n\t" +
  83. detail.toString();
  84. }
  85. }
  86. /**
  87. * Returns the cause of this exception. This method returns the value
  88. * of the {@link #detail} field.
  89. *
  90. * @return the cause, which may be <tt>null</tt>.
  91. * @since 1.4
  92. */
  93. public Throwable getCause() {
  94. return detail;
  95. }
  96. }