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