1. /*
  2. * @(#)WriteAbortedException.java 1.17 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.io;
  8. /**
  9. * Signals that one of the ObjectStreamExceptions was thrown during a
  10. * write operation. Thrown during a read operation when one of the
  11. * ObjectStreamExceptions was thrown during a write operation. The
  12. * exception that terminated the write can be found in the detail
  13. * field. The stream is reset to it's initial state and all references
  14. * to objects already deserialized are discarded.
  15. *
  16. * <p>As of release 1.4, this exception has been retrofitted to conform to
  17. * the general purpose exception-chaining mechanism. The "exception causing
  18. * the abort" that is provided at construction time and
  19. * accessed via the public {@link #detail} field is now known as the
  20. * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
  21. * method, as well as the aforementioned "legacy field."
  22. *
  23. * @author unascribed
  24. * @version 1.17, 01/23/03
  25. * @since JDK1.1
  26. */
  27. public class WriteAbortedException extends ObjectStreamException {
  28. static final long serialVersionUID = -3326426625597282442L;
  29. /**
  30. * Exception that was caught while writing the ObjectStream.
  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 Exception detail;
  39. /**
  40. * Constructs a WriteAbortedException with a string describing
  41. * the exception and the exception causing the abort.
  42. * @param s String describing the exception.
  43. * @param ex Exception causing the abort.
  44. */
  45. public WriteAbortedException(String s, Exception ex) {
  46. super(s);
  47. initCause(null); // Disallow subsequent initCause
  48. detail = ex;
  49. }
  50. /**
  51. * Produce the message and include the message from the nested
  52. * exception, if there is one.
  53. */
  54. public String getMessage() {
  55. if (detail == null)
  56. return super.getMessage();
  57. else
  58. return super.getMessage() + "; " + detail.toString();
  59. }
  60. /**
  61. * Returns the exception that terminated the operation (the <i>cause</i>).
  62. *
  63. * @return the exception that terminated the operation (the <i>cause</i>),
  64. * which may be null.
  65. * @since 1.4
  66. */
  67. public Throwable getCause() {
  68. return detail;
  69. }
  70. }