161 * Override toString to pick up any embedded exception. 162 * 163 * @return A string representation of this exception. 164 */ 165 public String toString () 166 { 167 Throwable exception = super.getCause(); 168 if (exception != null) { 169 return super.toString() + "\n" + exception.toString(); 170 } else { 171 return super.toString(); 172 } 173 } 174 175 176 177 ////////////////////////////////////////////////////////////////////// 178 // Internal state. 179 ////////////////////////////////////////////////////////////////////// 180 181 private static final ObjectStreamField[] serialPersistentFields = { 182 new ObjectStreamField( "exception", Exception.class ) 183 }; 184 185 /** 186 * Writes "exception" field to the stream. 187 * 188 * @param out stream used for serialization. 189 * @throws IOException thrown by <code>ObjectOutputStream</code> 190 */ 191 private void writeObject(ObjectOutputStream out) 192 throws IOException { 193 ObjectOutputStream.PutField fields = out.putFields(); 194 fields.put("exception", getExceptionInternal()); 195 out.writeFields(); 196 } 197 198 /** 199 * Reads the "exception" field from the stream. 200 * And initializes the "exception" if it wasn't 201 * done before. 202 * 203 * @param in stream used for deserialization 204 * @throws IOException thrown by <code>ObjectInputStream</code> 205 * @throws ClassNotFoundException thrown by <code>ObjectInputStream</code> 206 */ 207 private void readObject(ObjectInputStream in) 208 throws IOException, ClassNotFoundException { 209 ObjectInputStream.GetField fields = in.readFields(); 210 Exception exception = (Exception) fields.get("exception", null); 211 Throwable superCause = super.getCause(); 212 213 // if super.getCause() and 'exception' fields present then always use 214 // getCause() value. Otherwise, use 'exception' to initialize cause 215 if (superCause == null && exception != null) { 216 try { 217 super.initCause(exception); 218 } catch (IllegalStateException e) { 219 throw new InvalidClassException("Inconsistent state: two causes"); 220 } 221 } 222 } 223 224 // Internal method to guard against overriding of public getException 225 // method by SAXException subclasses 226 private Exception getExceptionInternal() { 227 Throwable cause = super.getCause(); 228 if (cause instanceof Exception) { 229 return (Exception) cause; 230 } else { 231 return null; 232 } 233 } 234 235 // Added serialVersionUID to preserve binary compatibility 236 static final long serialVersionUID = 583241635256073760L; 237 } 238 239 // end of SAXException.java | 161 * Override toString to pick up any embedded exception. 162 * 163 * @return A string representation of this exception. 164 */ 165 public String toString () 166 { 167 Throwable exception = super.getCause(); 168 if (exception != null) { 169 return super.toString() + "\n" + exception.toString(); 170 } else { 171 return super.toString(); 172 } 173 } 174 175 176 177 ////////////////////////////////////////////////////////////////////// 178 // Internal state. 179 ////////////////////////////////////////////////////////////////////// 180 181 @java.io.Serial 182 private static final ObjectStreamField[] serialPersistentFields = { 183 new ObjectStreamField( "exception", Exception.class ) 184 }; 185 186 /** 187 * Writes "exception" field to the stream. 188 * 189 * @param out stream used for serialization. 190 * @throws IOException thrown by <code>ObjectOutputStream</code> 191 */ 192 @java.io.Serial 193 private void writeObject(ObjectOutputStream out) 194 throws IOException { 195 ObjectOutputStream.PutField fields = out.putFields(); 196 fields.put("exception", getExceptionInternal()); 197 out.writeFields(); 198 } 199 200 /** 201 * Reads the "exception" field from the stream. 202 * And initializes the "exception" if it wasn't 203 * done before. 204 * 205 * @param in stream used for deserialization 206 * @throws IOException thrown by <code>ObjectInputStream</code> 207 * @throws ClassNotFoundException thrown by <code>ObjectInputStream</code> 208 */ 209 @java.io.Serial 210 private void readObject(ObjectInputStream in) 211 throws IOException, ClassNotFoundException { 212 ObjectInputStream.GetField fields = in.readFields(); 213 Exception exception = (Exception) fields.get("exception", null); 214 Throwable superCause = super.getCause(); 215 216 // if super.getCause() and 'exception' fields present then always use 217 // getCause() value. Otherwise, use 'exception' to initialize cause 218 if (superCause == null && exception != null) { 219 try { 220 super.initCause(exception); 221 } catch (IllegalStateException e) { 222 throw new InvalidClassException("Inconsistent state: two causes"); 223 } 224 } 225 } 226 227 // Internal method to guard against overriding of public getException 228 // method by SAXException subclasses 229 private Exception getExceptionInternal() { 230 Throwable cause = super.getCause(); 231 if (cause instanceof Exception) { 232 return (Exception) cause; 233 } else { 234 return null; 235 } 236 } 237 238 // Added serialVersionUID to preserve binary compatibility 239 @java.io.Serial 240 static final long serialVersionUID = 583241635256073760L; 241 } 242 243 // end of SAXException.java |