1. // $Id: XPathException.java,v 1.14.12.2 2004/06/15 00:07:08 rameshm Exp $
  2. /*
  3. * @(#)XPathException.java 1.8 04/07/26
  4. *
  5. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  6. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  7. */
  8. package javax.xml.xpath;
  9. import java.io.PrintWriter;
  10. /**
  11. * <code>XPathException</code> represents a generic XPath exception.</p>
  12. *
  13. * @author <a href="Norman.Walsh@Sun.com">Norman Walsh</a>
  14. * @author <a href="mailto:Jeff.Suttor@Sun.COM">Jeff Suttor</a>
  15. * @version $Revision: 1.14.12.2 $, $Date: 2004/06/15 00:07:08 $
  16. * @since 1.5
  17. */
  18. public class XPathException extends Exception {
  19. private final Throwable cause;
  20. /**
  21. * <p>Stream Unique Identifier.</p>
  22. */
  23. private static final long serialVersionUID = -1837080260374986980L;
  24. /**
  25. * <p>Constructs a new <code>XPathException</code> with the specified detail <code>message</code>.</p>
  26. *
  27. * <p>The <code>cause</code> is not initialized.</p>
  28. *
  29. * <p>If <code>message</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
  30. *
  31. * @param message The detail message.
  32. */
  33. public XPathException(String message) {
  34. super(message);
  35. if ( message == null ) {
  36. throw new NullPointerException ( "message can't be null");
  37. }
  38. this.cause = null;
  39. }
  40. /**
  41. * <p>Constructs a new <code>XPathException</code> with the specified <code>cause</code>.</p>
  42. *
  43. * <p>If <code>cause</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.</p>
  44. *
  45. * @param cause The cause.
  46. *
  47. * @throws NullPointerException if <code>cause</code> is <code>null</code>.
  48. */
  49. public XPathException(Throwable cause) {
  50. super();
  51. this.cause = cause;
  52. if ( cause == null ) {
  53. throw new NullPointerException ( "cause can't be null");
  54. }
  55. }
  56. public Throwable getCause() {
  57. return cause;
  58. }
  59. public void printStackTrace( java.io.PrintStream s ) {
  60. if( getCause() != null ) {
  61. getCause().printStackTrace(s);
  62. s.println("--------------- linked to ------------------");
  63. }
  64. super.printStackTrace(s);
  65. }
  66. public void printStackTrace() {
  67. printStackTrace(System.err);
  68. }
  69. public void printStackTrace(PrintWriter s) {
  70. if( getCause() != null ) {
  71. getCause().printStackTrace(s);
  72. s.println("--------------- linked to ------------------");
  73. }
  74. super.printStackTrace(s);
  75. }
  76. }