rt/emul/compact/src/main/java/java/io/WriteAbortedException.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 601 emul/compact/src/main/java/java/io/WriteAbortedException.java@5198affdb915
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
jaroslav@601
     1
/*
jaroslav@601
     2
 * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
jaroslav@601
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@601
     4
 *
jaroslav@601
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@601
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@601
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@601
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@601
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@601
    10
 *
jaroslav@601
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@601
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@601
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@601
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@601
    15
 * accompanied this code).
jaroslav@601
    16
 *
jaroslav@601
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@601
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@601
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@601
    20
 *
jaroslav@601
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@601
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@601
    23
 * questions.
jaroslav@601
    24
 */
jaroslav@601
    25
jaroslav@601
    26
package java.io;
jaroslav@601
    27
jaroslav@601
    28
/**
jaroslav@601
    29
 * Signals that one of the ObjectStreamExceptions was thrown during a
jaroslav@601
    30
 * write operation.  Thrown during a read operation when one of the
jaroslav@601
    31
 * ObjectStreamExceptions was thrown during a write operation.  The
jaroslav@601
    32
 * exception that terminated the write can be found in the detail
jaroslav@601
    33
 * field. The stream is reset to it's initial state and all references
jaroslav@601
    34
 * to objects already deserialized are discarded.
jaroslav@601
    35
 *
jaroslav@601
    36
 * <p>As of release 1.4, this exception has been retrofitted to conform to
jaroslav@601
    37
 * the general purpose exception-chaining mechanism.  The "exception causing
jaroslav@601
    38
 * the abort" that is provided at construction time and
jaroslav@601
    39
 * accessed via the public {@link #detail} field is now known as the
jaroslav@601
    40
 * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
jaroslav@601
    41
 * method, as well as the aforementioned "legacy field."
jaroslav@601
    42
 *
jaroslav@601
    43
 * @author  unascribed
jaroslav@601
    44
 * @since   JDK1.1
jaroslav@601
    45
 */
jaroslav@601
    46
public class WriteAbortedException extends ObjectStreamException {
jaroslav@601
    47
    private static final long serialVersionUID = -3326426625597282442L;
jaroslav@601
    48
jaroslav@601
    49
    /**
jaroslav@601
    50
     * Exception that was caught while writing the ObjectStream.
jaroslav@601
    51
     *
jaroslav@601
    52
     * <p>This field predates the general-purpose exception chaining facility.
jaroslav@601
    53
     * The {@link Throwable#getCause()} method is now the preferred means of
jaroslav@601
    54
     * obtaining this information.
jaroslav@601
    55
     *
jaroslav@601
    56
     * @serial
jaroslav@601
    57
     */
jaroslav@601
    58
    public Exception detail;
jaroslav@601
    59
jaroslav@601
    60
    /**
jaroslav@601
    61
     * Constructs a WriteAbortedException with a string describing
jaroslav@601
    62
     * the exception and the exception causing the abort.
jaroslav@601
    63
     * @param s   String describing the exception.
jaroslav@601
    64
     * @param ex  Exception causing the abort.
jaroslav@601
    65
     */
jaroslav@601
    66
    public WriteAbortedException(String s, Exception ex) {
jaroslav@601
    67
        super(s);
jaroslav@601
    68
        initCause(null);  // Disallow subsequent initCause
jaroslav@601
    69
        detail = ex;
jaroslav@601
    70
    }
jaroslav@601
    71
jaroslav@601
    72
    /**
jaroslav@601
    73
     * Produce the message and include the message from the nested
jaroslav@601
    74
     * exception, if there is one.
jaroslav@601
    75
     */
jaroslav@601
    76
    public String getMessage() {
jaroslav@601
    77
        if (detail == null)
jaroslav@601
    78
            return super.getMessage();
jaroslav@601
    79
        else
jaroslav@601
    80
            return super.getMessage() + "; " + detail.toString();
jaroslav@601
    81
    }
jaroslav@601
    82
jaroslav@601
    83
    /**
jaroslav@601
    84
     * Returns the exception that terminated the operation (the <i>cause</i>).
jaroslav@601
    85
     *
jaroslav@601
    86
     * @return  the exception that terminated the operation (the <i>cause</i>),
jaroslav@601
    87
     *          which may be null.
jaroslav@601
    88
     * @since   1.4
jaroslav@601
    89
     */
jaroslav@601
    90
    public Throwable getCause() {
jaroslav@601
    91
        return detail;
jaroslav@601
    92
    }
jaroslav@601
    93
}