1. /*
  2. * @(#)RemoteException.java 1.17 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.rmi;
  11. /**
  12. * A <code>RemoteException</code> is the common superclass for a number of
  13. * communication-related exceptions that may occur during the execution of a
  14. * remote method call. Each method of a remote interface, an interface that
  15. * extends <code>java.rmi.Remote</code>, must list
  16. * <code>RemoteException</code> in its throws clause.
  17. *
  18. * @version 1.17, 02/02/00
  19. * @author Ann Wollrath
  20. * @since JDK1.1
  21. */
  22. public class RemoteException extends java.io.IOException {
  23. /* indicate compatibility with JDK 1.1.x version of class */
  24. private static final long serialVersionUID = -5148567311918794206L;
  25. /**
  26. * Nested Exception to hold wrapped remote exception.
  27. *
  28. * @serial
  29. * @since JDK1.1
  30. */
  31. public Throwable detail;
  32. /**
  33. * Constructs a <code>RemoteException</code> with no specified
  34. * detail message.
  35. * @since JDK1.1
  36. */
  37. public RemoteException() {}
  38. /**
  39. * Constructs a <code>RemoteException</code> with the specified
  40. * detail message.
  41. *
  42. * @param s the detail message
  43. * @since JDK1.1
  44. */
  45. public RemoteException(String s) {
  46. super(s);
  47. }
  48. /**
  49. * Constructs a <code>RemoteException</code> with the specified
  50. * detail message and nested exception.
  51. *
  52. * @param s the detail message
  53. * @param ex the nested exception
  54. * @since JDK1.1
  55. */
  56. public RemoteException(String s, Throwable ex) {
  57. super(s);
  58. detail = ex;
  59. }
  60. /**
  61. * Returns the detail message, including the message from the nested
  62. * exception if there is one.
  63. * @since JDK1.1
  64. */
  65. public String getMessage() {
  66. if (detail == null)
  67. return super.getMessage();
  68. else
  69. return super.getMessage() +
  70. "; nested exception is: \n\t" +
  71. detail.toString();
  72. }
  73. /**
  74. * Prints the composite message and the embedded stack trace to
  75. * the specified stream <code>ps</code>.
  76. * @param ps the print stream
  77. * @since 1.2
  78. */
  79. public void printStackTrace(java.io.PrintStream ps)
  80. {
  81. if (detail == null) {
  82. super.printStackTrace(ps);
  83. } else {
  84. synchronized(ps) {
  85. ps.println(this);
  86. detail.printStackTrace(ps);
  87. }
  88. }
  89. }
  90. /**
  91. * Prints the composite message to <code>System.err</code>.
  92. * @since 1.2
  93. */
  94. public void printStackTrace()
  95. {
  96. printStackTrace(System.err);
  97. }
  98. /**
  99. * Prints the composite message and the embedded stack trace to
  100. * the specified print writer <code>pw</code>.
  101. * @param pw the print writer
  102. * @since 1.2
  103. */
  104. public void printStackTrace(java.io.PrintWriter pw)
  105. {
  106. if (detail == null) {
  107. super.printStackTrace(pw);
  108. } else {
  109. synchronized(pw) {
  110. pw.println(this);
  111. detail.printStackTrace(pw);
  112. }
  113. }
  114. }
  115. }