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 */ 30public class WriteAbortedException extends ObjectStreamException { 31 32 private static final long serialVersionUID = -3326426625597282442L; 33 34 /** 35 * The exception that occured when writeObject() was attempting to serialize 36 * the object. 37 */ 38 public Exception detail; 39 40 /** 41 * Constructs a new {@code WriteAbortedException} with its stack trace, 42 * detail message and the exception which caused the underlying problem when 43 * serializing the object filled in. 44 * 45 * @param detailMessage 46 * the detail message for this exception. 47 * @param rootCause 48 * the exception that was thrown when serializing the object. 49 */ 50 public WriteAbortedException(String detailMessage, Exception rootCause) { 51 super(detailMessage); 52 detail = rootCause; 53 initCause(rootCause); 54 } 55 56 /** 57 * Gets the extra information message which was provided when this exception 58 * was created. Returns {@code null} if no message was provided at creation 59 * time. 60 * 61 * @return the exception message. 62 */ 63 @Override 64 public String getMessage() { 65 String msg = super.getMessage(); 66 if (detail != null) { 67 msg = msg + "; " + detail.toString(); 68 } 69 return msg; 70 } 71 72 /** 73 * Gets the cause of this exception or {@code null} if there is no cause. 74 * 75 * @return the exception cause. 76 */ 77 @Override 78 public Throwable getCause() { 79 return detail; 80 } 81} 82