01: /*
02: * @(#)WriteAbortedException.java 1.19 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: *
26: */
27:
28: package java.io;
29:
30: /**
31: * Signals that one of the ObjectStreamExceptions was thrown during a
32: * write operation. Thrown during a read operation when one of the
33: * ObjectStreamExceptions was thrown during a write operation. The
34: * exception that terminated the write can be found in the detail
35: * field. The stream is reset to it's initial state and all references
36: * to objects already deserialized are discarded.
37: *
38: * <p>As of release 1.4, this exception has been retrofitted to conform to
39: * the general purpose exception-chaining mechanism. The "exception causing
40: * the abort" that is provided at construction time and
41: * accessed via the public {@link #detail} field is now known as the
42: * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
43: * method, as well as the aforementioned "legacy field."
44: *
45: * @author unascribed
46: * @version 1.12, 02/02/00
47: * @since JDK1.1
48: */
49: public class WriteAbortedException extends ObjectStreamException {
50: static final long serialVersionUID = -3326426625597282442L;
51:
52: /**
53: * Exception that was caught while writing the ObjectStream.
54: *
55: * <p>This field predates the general-purpose exception chaining facility.
56: * The {@link Throwable#getCause()} method is now the preferred means of
57: * obtaining this information.
58: *
59: * @serial
60: */
61: public Exception detail;
62:
63: /**
64: * Constructs a WriteAbortedException with a string describing
65: * the exception and the exception causing the abort.
66: * @param s String describing the exception.
67: * @param ex Exception causing the abort.
68: */
69: public WriteAbortedException(String s, Exception ex) {
70: super (s);
71: initCause(null); // Disallow subsequent initCause
72: detail = ex;
73: }
74:
75: /**
76: * Produce the message and include the message from the nested
77: * exception, if there is one.
78: */
79: public String getMessage() {
80: if (detail == null)
81: return super .getMessage();
82: else
83: return super .getMessage() + "; " + detail.toString();
84: }
85:
86: /**
87: * Returns the exception that terminated the operation (the <i>cause</i>).
88: *
89: * @return the exception that terminated the operation (the <i>cause</i>),
90: * which may be null.
91: * @since 1.4
92: */
93: public Throwable getCause() {
94: return detail;
95: }
96: }
|