1. /*
  2. * @(#)RemoteException.java 1.22 03/01/23
  3. *
  4. * Copyright 2003 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. * @version 1.22, 01/23/03
  23. * @author Ann Wollrath
  24. * @since JDK1.1
  25. */
  26. public class RemoteException extends java.io.IOException {
  27. /* indicate compatibility with JDK 1.1.x version of class */
  28. private static final long serialVersionUID = -5148567311918794206L;
  29. /**
  30. * Nested Exception to hold wrapped remote exception.
  31. *
  32. * <p>This field predates the general-purpose exception chaining facility.
  33. * The {@link Throwable#getCause()} method is now the preferred means of
  34. * obtaining this information.
  35. *
  36. * @serial
  37. */
  38. public Throwable detail;
  39. /**
  40. * Constructs a <code>RemoteException</code> with no specified
  41. * detail message.
  42. */
  43. public RemoteException() {
  44. initCause(null); // Disallow subsequent initCause
  45. }
  46. /**
  47. * Constructs a <code>RemoteException</code> with the specified
  48. * detail message.
  49. *
  50. * @param s the detail message
  51. */
  52. public RemoteException(String s) {
  53. super(s);
  54. initCause(null); // Disallow subsequent initCause
  55. }
  56. /**
  57. * Constructs a <code>RemoteException</code> with the specified
  58. * detail message and nested exception.
  59. *
  60. * @param s the detail message
  61. * @param ex the nested exception
  62. */
  63. public RemoteException(String s, Throwable ex) {
  64. super(s);
  65. initCause(null); // Disallow subsequent initCause
  66. detail = ex;
  67. }
  68. /**
  69. * Returns the detail message, including the message from the nested
  70. * exception if there is one.
  71. *
  72. * @return the detail message, including nested exception message if any
  73. */
  74. public String getMessage() {
  75. if (detail == null) {
  76. return super.getMessage();
  77. } else {
  78. return super.getMessage() + "; nested exception is: \n\t" +
  79. detail.toString();
  80. }
  81. }
  82. /**
  83. * Returns the wrapped remote exception (the <i>cause</i>).
  84. *
  85. * @return the wrapped remote exception, which may be <tt>null</tt>.
  86. * @since 1.4
  87. */
  88. public Throwable getCause() {
  89. return detail;
  90. }
  91. }