1. // SAX exception class.
  2. // http://www.saxproject.org
  3. // No warranty; no copyright -- use this as you will.
  4. // $Id: SAXException.java,v 1.2.24.1.2.1 2004/06/08 22:44:56 rameshm Exp $
  5. package org.xml.sax;
  6. /**
  7. * Encapsulate a general SAX error or warning.
  8. *
  9. * <blockquote>
  10. * <em>This module, both source code and documentation, is in the
  11. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  12. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  13. * for further information.
  14. * </blockquote>
  15. *
  16. * <p>This class can contain basic error or warning information from
  17. * either the XML parser or the application: a parser writer or
  18. * application writer can subclass it to provide additional
  19. * functionality. SAX handlers may throw this exception or
  20. * any exception subclassed from it.</p>
  21. *
  22. * <p>If the application needs to pass through other types of
  23. * exceptions, it must wrap those exceptions in a SAXException
  24. * or an exception derived from a SAXException.</p>
  25. *
  26. * <p>If the parser or application needs to include information about a
  27. * specific location in an XML document, it should use the
  28. * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
  29. *
  30. * @since SAX 1.0
  31. * @author David Megginson
  32. * @version 2.0.1 (sax2r2)
  33. * @see org.xml.sax.SAXParseException
  34. */
  35. public class SAXException extends Exception {
  36. /**
  37. * Create a new SAXException.
  38. */
  39. public SAXException ()
  40. {
  41. super();
  42. this.exception = null;
  43. }
  44. /**
  45. * Create a new SAXException.
  46. *
  47. * @param message The error or warning message.
  48. */
  49. public SAXException (String message) {
  50. super(message);
  51. this.exception = null;
  52. }
  53. /**
  54. * Create a new SAXException wrapping an existing exception.
  55. *
  56. * <p>The existing exception will be embedded in the new
  57. * one, and its message will become the default message for
  58. * the SAXException.</p>
  59. *
  60. * @param e The exception to be wrapped in a SAXException.
  61. */
  62. public SAXException (Exception e)
  63. {
  64. super();
  65. this.exception = e;
  66. }
  67. /**
  68. * Create a new SAXException from an existing exception.
  69. *
  70. * <p>The existing exception will be embedded in the new
  71. * one, but the new exception will have its own message.</p>
  72. *
  73. * @param message The detail message.
  74. * @param e The exception to be wrapped in a SAXException.
  75. */
  76. public SAXException (String message, Exception e)
  77. {
  78. super(message);
  79. this.exception = e;
  80. }
  81. /**
  82. * Return a detail message for this exception.
  83. *
  84. * <p>If there is an embedded exception, and if the SAXException
  85. * has no detail message of its own, this method will return
  86. * the detail message from the embedded exception.</p>
  87. *
  88. * @return The error or warning message.
  89. */
  90. public String getMessage ()
  91. {
  92. String message = super.getMessage();
  93. if (message == null && exception != null) {
  94. return exception.getMessage();
  95. } else {
  96. return message;
  97. }
  98. }
  99. /**
  100. * Return the embedded exception, if any.
  101. *
  102. * @return The embedded exception, or null if there is none.
  103. */
  104. public Exception getException ()
  105. {
  106. return exception;
  107. }
  108. /**
  109. * Override toString to pick up any embedded exception.
  110. *
  111. * @return A string representation of this exception.
  112. */
  113. public String toString ()
  114. {
  115. if (exception != null) {
  116. return exception.toString();
  117. } else {
  118. return super.toString();
  119. }
  120. }
  121. //////////////////////////////////////////////////////////////////////
  122. // Internal state.
  123. //////////////////////////////////////////////////////////////////////
  124. /**
  125. * @serial The embedded exception if tunnelling, or null.
  126. */
  127. private Exception exception;
  128. // Added serialVersionUID to preserve binary compatibility
  129. static final long serialVersionUID = 583241635256073760L;
  130. }
  131. // end of SAXException.java