001: // SAX exception class.
002: // No warranty; no copyright -- use this as you will.
003: // $Id: SAXException.java,v 1.2 2005/03/25 14:58:33 csilva Exp $
004:
005: package org.xml.sax;
006:
007: /**
008: * Encapsulate a general SAX error or warning.
009: *
010: * <p>This class can contain basic error or warning information from
011: * either the XML parser or the application: a parser writer or
012: * application writer can subclass it to provide additional
013: * functionality. SAX handlers may throw this exception or
014: * any exception subclassed from it.</p>
015: *
016: * <p>If the application needs to pass through other types of
017: * exceptions, it must wrap those exceptions in a SAXException
018: * or an exception derived from a SAXException.</p>
019: *
020: * <p>If the parser or application needs to include information about a
021: * specific location in an XML document, it should use the
022: * SAXParseException subclass.</p>
023: *
024: * @author David Megginson (ak117@freenet.carleton.ca)
025: * @version 1.0
026: * @see org.xml.sax.SAXParseException
027: */
028: public class SAXException extends Exception {
029: private static final long serialVersionUID = 3834871373422999091L;
030:
031: /**
032: * Create a new SAXException.
033: *
034: * @param message The error or warning message.
035: * @see org.xml.sax.Parser#setLocale
036: */
037: public SAXException(String message) {
038: super ();
039: this .message = message;
040: this .exception = null;
041: }
042:
043: /**
044: * Create a new SAXException wrapping an existing exception.
045: *
046: * <p>The existing exception will be embedded in the new
047: * one, and its message will become the default message for
048: * the SAXException.</p>
049: *
050: * @param e The exception to be wrapped in a SAXException.
051: */
052: public SAXException(Exception e) {
053: super ();
054: this .message = null;
055: this .exception = e;
056: }
057:
058: /**
059: * Create a new SAXException from an existing exception.
060: *
061: * <p>The existing exception will be embedded in the new
062: * one, but the new exception will have its own message.</p>
063: *
064: * @param message The detail message.
065: * @param e The exception to be wrapped in a SAXException.
066: * @see org.xml.sax.Parser#setLocale
067: */
068: public SAXException(String message, Exception e) {
069: super ();
070: this .message = message;
071: this .exception = e;
072: }
073:
074: /**
075: * Return a detail message for this exception.
076: *
077: * <p>If there is a embedded exception, and if the SAXException
078: * has no detail message of its own, this method will return
079: * the detail message from the embedded exception.</p>
080: *
081: * @return The error or warning message.
082: * @see org.xml.sax.Parser#setLocale
083: */
084: public String getMessage() {
085: if (message == null && exception != null) {
086: return exception.getMessage();
087: } else {
088: return this .message;
089: }
090: }
091:
092: /**
093: * Return the embedded exception, if any.
094: *
095: * @return The embedded exception, or null if there is none.
096: */
097: public Exception getException() {
098: return exception;
099: }
100:
101: /**
102: * Convert this exception to a string.
103: *
104: * @return A string version of this exception.
105: */
106: public String toString() {
107: return getMessage();
108: }
109:
110: //////////////////////////////////////////////////////////////////////
111: // Internal state.
112: //////////////////////////////////////////////////////////////////////
113:
114: private String message;
115: private Exception exception;
116:
117: }
|