001: // SAX exception class.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004:
005: package org.xml.sax;
006:
007: /**
008: * Encapsulate a general SAX error or warning.
009: *
010: * <blockquote>
011: * <em>This module, both source code and documentation, is in the
012: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
013: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
014: * for further information.
015: * </blockquote>
016: *
017: * <p>This class can contain basic error or warning information from
018: * either the XML parser or the application: a parser writer or
019: * application writer can subclass it to provide additional
020: * functionality. SAX handlers may throw this exception or
021: * any exception subclassed from it.</p>
022: *
023: * <p>If the application needs to pass through other types of
024: * exceptions, it must wrap those exceptions in a SAXException
025: * or an exception derived from a SAXException.</p>
026: *
027: * <p>If the parser or application needs to include information about a
028: * specific location in an XML document, it should use the
029: * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
030: *
031: * @since SAX 1.0
032: * @author David Megginson
033: * @version 2.0.1 (sax2r2)
034: * @see org.xml.sax.SAXParseException
035: */
036: public class SAXException extends Exception {
037:
038: /**
039: * Create a new SAXException.
040: */
041: public SAXException() {
042: super ();
043: this .exception = null;
044: }
045:
046: /**
047: * Create a new SAXException.
048: *
049: * @param message The error or warning message.
050: */
051: public SAXException(String message) {
052: super (message);
053: this .exception = null;
054: }
055:
056: /**
057: * Create a new SAXException wrapping an existing exception.
058: *
059: * <p>The existing exception will be embedded in the new
060: * one, and its message will become the default message for
061: * the SAXException.</p>
062: *
063: * @param e The exception to be wrapped in a SAXException.
064: */
065: public SAXException(Exception e) {
066: super ();
067: this .exception = e;
068: }
069:
070: /**
071: * Create a new SAXException from an existing exception.
072: *
073: * <p>The existing exception will be embedded in the new
074: * one, but the new exception will have its own message.</p>
075: *
076: * @param message The detail message.
077: * @param e The exception to be wrapped in a SAXException.
078: */
079: public SAXException(String message, Exception e) {
080: super (message);
081: this .exception = e;
082: }
083:
084: /**
085: * Return a detail message for this exception.
086: *
087: * <p>If there is an embedded exception, and if the SAXException
088: * has no detail message of its own, this method will return
089: * the detail message from the embedded exception.</p>
090: *
091: * @return The error or warning message.
092: */
093: public String getMessage() {
094: String message = super .getMessage();
095:
096: if (message == null && exception != null) {
097: return exception.getMessage();
098: } else {
099: return message;
100: }
101: }
102:
103: /**
104: * Return the embedded exception, if any.
105: *
106: * @return The embedded exception, or null if there is none.
107: */
108: public Exception getException() {
109: return exception;
110: }
111:
112: /**
113: * Override toString to pick up any embedded exception.
114: *
115: * @return A string representation of this exception.
116: */
117: public String toString() {
118: if (exception != null) {
119: return exception.toString();
120: } else {
121: return super .toString();
122: }
123: }
124:
125: //////////////////////////////////////////////////////////////////////
126: // Internal state.
127: //////////////////////////////////////////////////////////////////////
128:
129: /**
130: * @serial The embedded exception if tunnelling, or null.
131: */
132: private Exception exception;
133:
134: }
135:
136: // end of SAXException.java
|