KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > io > WriteAbortedException


1 /*
2  * @(#)WriteAbortedException.java 1.18 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
8 package java.io;
9
10 /**
11  * Signals that one of the ObjectStreamExceptions was thrown during a
12  * write operation. Thrown during a read operation when one of the
13  * ObjectStreamExceptions was thrown during a write operation. The
14  * exception that terminated the write can be found in the detail
15  * field. The stream is reset to it's initial state and all references
16  * to objects already deserialized are discarded.
17  *
18  * <p>As of release 1.4, this exception has been retrofitted to conform to
19  * the general purpose exception-chaining mechanism. The "exception causing
20  * the abort" that is provided at construction time and
21  * accessed via the public {@link #detail} field is now known as the
22  * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
23  * method, as well as the aforementioned "legacy field."
24  *
25  * @author unascribed
26  * @version 1.18, 12/19/03
27  * @since JDK1.1
28  */

29 public class WriteAbortedException extends ObjectStreamException JavaDoc {
30     static final long serialVersionUID = -3326426625597282442L;
31
32     /**
33      * Exception that was caught while writing the ObjectStream.
34      *
35      * <p>This field predates the general-purpose exception chaining facility.
36      * The {@link Throwable#getCause()} method is now the preferred means of
37      * obtaining this information.
38      *
39      * @serial
40      */

41     public Exception JavaDoc detail;
42
43     /**
44      * Constructs a WriteAbortedException with a string describing
45      * the exception and the exception causing the abort.
46      * @param s String describing the exception.
47      * @param ex Exception causing the abort.
48      */

49     public WriteAbortedException(String JavaDoc s, Exception JavaDoc ex) {
50     super(s);
51         initCause(null); // Disallow subsequent initCause
52
detail = ex;
53     }
54
55     /**
56      * Produce the message and include the message from the nested
57      * exception, if there is one.
58      */

59     public String JavaDoc getMessage() {
60     if (detail == null)
61         return super.getMessage();
62     else
63         return super.getMessage() + "; " + detail.toString();
64     }
65
66     /**
67      * Returns the exception that terminated the operation (the <i>cause</i>).
68      *
69      * @return the exception that terminated the operation (the <i>cause</i>),
70      * which may be null.
71      * @since 1.4
72      */

73     public Throwable JavaDoc getCause() {
74         return detail;
75     }
76 }
77
Popular Tags