Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/xpath/XPathException.java
32285 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.xpath;2627import java.io.PrintWriter;28import java.io.IOException;29import java.io.ObjectInputStream;30import java.io.ObjectOutputStream;31import java.io.ObjectStreamField;32import java.io.InvalidClassException;3334/**35* <code>XPathException</code> represents a generic XPath exception.</p>36*37* @author <a href="[email protected]">Norman Walsh</a>38* @author <a href="mailto:[email protected]">Jeff Suttor</a>39* @since 1.540*/41public class XPathException extends Exception {4243private static final ObjectStreamField[] serialPersistentFields = {44new ObjectStreamField( "cause", Throwable.class )45};4647/**48* <p>Stream Unique Identifier.</p>49*/50private static final long serialVersionUID = -1837080260374986980L;5152/**53* <p>Constructs a new <code>XPathException</code>54* with the specified detail <code>message</code>.</p>55*56* <p>The <code>cause</code> is not initialized.</p>57*58* <p>If <code>message</code> is <code>null</code>,59* then a <code>NullPointerException</code> is thrown.</p>60*61* @param message The detail message.62*63* @throws NullPointerException When <code>message</code> is64* <code>null</code>.65*/66public XPathException(String message) {67super(message);68if ( message == null ) {69throw new NullPointerException ( "message can't be null");70}71}7273/**74* <p>Constructs a new <code>XPathException</code>75* with the specified <code>cause</code>.</p>76*77* <p>If <code>cause</code> is <code>null</code>,78* then a <code>NullPointerException</code> is thrown.</p>79*80* @param cause The cause.81*82* @throws NullPointerException if <code>cause</code> is <code>null</code>.83*/84public XPathException(Throwable cause) {85super(cause);86if ( cause == null ) {87throw new NullPointerException ( "cause can't be null");88}89}9091/**92* <p>Get the cause of this XPathException.</p>93*94* @return Cause of this XPathException.95*/96public Throwable getCause() {97return super.getCause();98}99100/**101* Writes "cause" field to the stream.102* The cause is got from the parent class.103*104* @param out stream used for serialization.105* @throws IOException thrown by <code>ObjectOutputStream</code>106*107*/108private void writeObject(ObjectOutputStream out)109throws IOException110{111ObjectOutputStream.PutField fields = out.putFields();112fields.put("cause", (Throwable) super.getCause());113out.writeFields();114}115116/**117* Reads the "cause" field from the stream.118* And initializes the "cause" if it wasn't119* done before.120*121* @param in stream used for deserialization122* @throws IOException thrown by <code>ObjectInputStream</code>123* @throws ClassNotFoundException thrown by <code>ObjectInputStream</code>124*/125private void readObject(ObjectInputStream in)126throws IOException, ClassNotFoundException127{128ObjectInputStream.GetField fields = in.readFields();129Throwable scause = (Throwable) fields.get("cause", null);130131if (super.getCause() == null && scause != null) {132try {133super.initCause(scause);134} catch(IllegalStateException e) {135throw new InvalidClassException("Inconsistent state: two causes");136}137}138}139140/**141* <p>Print stack trace to specified <code>PrintStream</code>.</p>142*143* @param s Print stack trace to this <code>PrintStream</code>.144*/145public void printStackTrace(java.io.PrintStream s) {146if (getCause() != null) {147getCause().printStackTrace(s);148s.println("--------------- linked to ------------------");149}150151super.printStackTrace(s);152}153154/**155* <p>Print stack trace to <code>System.err</code>.</p>156*/157public void printStackTrace() {158printStackTrace(System.err);159}160161/**162* <p>Print stack trace to specified <code>PrintWriter</code>.</p>163*164* @param s Print stack trace to this <code>PrintWriter</code>.165*/166public void printStackTrace(PrintWriter s) {167168if (getCause() != null) {169getCause().printStackTrace(s);170s.println("--------------- linked to ------------------");171}172173super.printStackTrace(s);174}175}176177178