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 // $Id: XPathException.java 446598 2006-09-15 12:55:40Z jeremias $ 18 19 package javax.xml.xpath; 20 21 import java.io.PrintWriter; 22 23 /** 24 * <code>XPathException</code> represents a generic XPath exception.</p> 25 * 26 * @author <a href="Norman.Walsh@Sun.com">Norman Walsh</a> 27 * @author <a href="mailto:Jeff.Suttor@Sun.COM">Jeff Suttor</a> 28 * @version $Revision: 446598 $, $Date: 2006-09-15 05:55:40 -0700 (Fri, 15 Sep 2006) $ 29 * @since 1.5 30 */ 31 public class XPathException extends Exception { 32 33 private final Throwable cause; 34 35 /** 36 * <p>Stream Unique Identifier.</p> 37 */ 38 private static final long serialVersionUID = -1837080260374986980L; 39 40 /** 41 * <p>Constructs a new <code>XPathException</code> with the specified detail <code>message</code>.</p> 42 * 43 * <p>The <code>cause</code> is not initialized.</p> 44 * 45 * <p>If <code>message</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p> 46 * 47 * @param message The detail message. 48 */ XPathException(String message)49 public XPathException(String message) { 50 super(message); 51 if (message == null) { 52 throw new NullPointerException("message == null"); 53 } 54 this.cause = null; 55 } 56 57 /** 58 * <p>Constructs a new <code>XPathException</code> with the specified <code>cause</code>.</p> 59 * 60 * <p>If <code>cause</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p> 61 * 62 * @param cause The cause. 63 * 64 * @throws NullPointerException if <code>cause</code> is <code>null</code>. 65 */ XPathException(Throwable cause)66 public XPathException(Throwable cause) { 67 super(cause == null ? null : cause.toString()); 68 this.cause = cause; 69 if (cause == null) { 70 throw new NullPointerException("cause == null"); 71 } 72 } 73 getCause()74 public Throwable getCause() { 75 return cause; 76 } 77 printStackTrace( java.io.PrintStream s )78 public void printStackTrace( java.io.PrintStream s ) { 79 if( getCause() != null ) { 80 getCause().printStackTrace(s); 81 s.println("--------------- linked to ------------------"); 82 } 83 84 super.printStackTrace(s); 85 } 86 printStackTrace()87 public void printStackTrace() { 88 printStackTrace(System.err); 89 } 90 printStackTrace(PrintWriter s)91 public void printStackTrace(PrintWriter s) { 92 if( getCause() != null ) { 93 getCause().printStackTrace(s); 94 s.println("--------------- linked to ------------------"); 95 } 96 97 super.printStackTrace(s); 98 } 99 } 100