1. /*
  2. * @(#)RemoteException.java 1.13 01/11/29
  3. *
  4. * Copyright 2002 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. * @version 1.13, 11/29/01
  16. * @author Ann Wollrath
  17. * @since JDK1.1
  18. */
  19. public class RemoteException extends java.io.IOException {
  20. /* indicate compatibility with JDK 1.1.x version of class */
  21. private static final long serialVersionUID = -5148567311918794206L;
  22. /**
  23. * Nested Exception to hold wrapped remote exception.
  24. *
  25. * @serial
  26. * @since JDK1.1
  27. */
  28. public Throwable detail;
  29. /**
  30. * Constructs a <code>RemoteException</code> with no specified
  31. * detail message.
  32. * @since JDK1.1
  33. */
  34. public RemoteException() {}
  35. /**
  36. * Constructs a <code>RemoteException</code> with the specified
  37. * detail message.
  38. *
  39. * @param s the detail message
  40. * @since JDK1.1
  41. */
  42. public RemoteException(String s) {
  43. super(s);
  44. }
  45. /**
  46. * Constructs a <code>RemoteException</code> with the specified
  47. * detail message and nested exception.
  48. *
  49. * @param s the detail message
  50. * @param ex the nested exception
  51. * @since JDK1.1
  52. */
  53. public RemoteException(String s, Throwable ex) {
  54. super(s);
  55. detail = ex;
  56. }
  57. /**
  58. * Returns the detail message, including the message from the nested
  59. * exception if there is one.
  60. * @since JDK1.1
  61. */
  62. public String getMessage() {
  63. if (detail == null)
  64. return super.getMessage();
  65. else
  66. return super.getMessage() +
  67. "; nested exception is: \n\t" +
  68. detail.toString();
  69. }
  70. /**
  71. * Prints the composite message and the embedded stack trace to
  72. * the specified stream <code>ps</code>.
  73. * @param ps the print stream
  74. * @since JDK1.2
  75. */
  76. public void printStackTrace(java.io.PrintStream ps)
  77. {
  78. if (detail == null) {
  79. super.printStackTrace(ps);
  80. } else {
  81. synchronized(ps) {
  82. ps.println(this);
  83. detail.printStackTrace(ps);
  84. }
  85. }
  86. }
  87. /**
  88. * Prints the composite message to <code>System.err</code>.
  89. * @since JDK1.2
  90. */
  91. public void printStackTrace()
  92. {
  93. printStackTrace(System.err);
  94. }
  95. /**
  96. * Prints the composite message and the embedded stack trace to
  97. * the specified print writer <code>pw</code>
  98. * @param pw the print writer
  99. * @since JDK1.2
  100. */
  101. public void printStackTrace(java.io.PrintWriter pw)
  102. {
  103. if (detail == null) {
  104. super.printStackTrace(pw);
  105. } else {
  106. synchronized(pw) {
  107. pw.println(this);
  108. detail.printStackTrace(pw);
  109. }
  110. }
  111. }
  112. }