1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.io;
19
20/**
21 * Signals that the {@link ObjectInputStream#readObject()} method has detected
22 * an exception marker in the input stream. This marker indicates that exception
23 * occurred when the object was serialized, and this marker was inserted instead
24 * of the original object. It is a way to "propagate" an exception from the code
25 * that attempted to write the object to the code that is attempting to read the
26 * object.
27 *
28 * @see ObjectInputStream#readObject()
29 *
30 * @since Android 1.0
31 */
32public class WriteAbortedException extends ObjectStreamException {
33
34    private static final long serialVersionUID = -3326426625597282442L;
35
36    /**
37     * The exception that occured when writeObject() was attempting to serialize
38     * the object.
39     *
40     * @since Android 1.0
41     */
42    public Exception detail;
43
44    /**
45     * Constructs a new {@code WriteAbortedException} with its stack trace,
46     * detail message and the exception which caused the underlying problem when
47     * serializing the object filled in.
48     *
49     * @param detailMessage
50     *            the detail message for this exception.
51     * @param rootCause
52     *            the exception that was thrown when serializing the object.
53     * @since Android 1.0
54     */
55    public WriteAbortedException(String detailMessage, Exception rootCause) {
56        super(detailMessage);
57        detail = rootCause;
58        initCause(rootCause);
59    }
60
61    /**
62     * Gets the extra information message which was provided when this exception
63     * was created. Returns {@code null} if no message was provided at creation
64     * time.
65     *
66     * @return the exception message.
67     * @since Android 1.0
68     */
69    @Override
70    public String getMessage() {
71        String msg = super.getMessage();
72        if (detail != null) {
73            msg = msg + "; " + detail.toString(); //$NON-NLS-1$
74        }
75        return msg;
76    }
77
78    /**
79     * Gets the cause of this exception or {@code null} if there is no cause.
80     *
81     * @return the exception cause.
82     * @since Android 1.0
83     */
84    @Override
85    public Throwable getCause() {
86        return detail;
87    }
88}
89