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