001 /*
002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 // SAX exception class.
027 // http://www.saxproject.org
028 // No warranty; no copyright -- use this as you will.
029 // $Id: SAXException.java,v 1.3 2004/11/03 22:55:32 jsuttor Exp $
030 package org.xml.sax;
031
032 /**
033 * Encapsulate a general SAX error or warning.
034 *
035 * <blockquote>
036 * <em>This module, both source code and documentation, is in the
037 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
038 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
039 * for further information.
040 * </blockquote>
041 *
042 * <p>This class can contain basic error or warning information from
043 * either the XML parser or the application: a parser writer or
044 * application writer can subclass it to provide additional
045 * functionality. SAX handlers may throw this exception or
046 * any exception subclassed from it.</p>
047 *
048 * <p>If the application needs to pass through other types of
049 * exceptions, it must wrap those exceptions in a SAXException
050 * or an exception derived from a SAXException.</p>
051 *
052 * <p>If the parser or application needs to include information about a
053 * specific location in an XML document, it should use the
054 * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
055 *
056 * @since SAX 1.0
057 * @author David Megginson
058 * @version 2.0.1 (sax2r2)
059 * @see org.xml.sax.SAXParseException
060 */
061 public class SAXException extends Exception {
062
063 /**
064 * Create a new SAXException.
065 */
066 public SAXException() {
067 super ();
068 this .exception = null;
069 }
070
071 /**
072 * Create a new SAXException.
073 *
074 * @param message The error or warning message.
075 */
076 public SAXException(String message) {
077 super (message);
078 this .exception = null;
079 }
080
081 /**
082 * Create a new SAXException wrapping an existing exception.
083 *
084 * <p>The existing exception will be embedded in the new
085 * one, and its message will become the default message for
086 * the SAXException.</p>
087 *
088 * @param e The exception to be wrapped in a SAXException.
089 */
090 public SAXException(Exception e) {
091 super ();
092 this .exception = e;
093 }
094
095 /**
096 * Create a new SAXException from an existing exception.
097 *
098 * <p>The existing exception will be embedded in the new
099 * one, but the new exception will have its own message.</p>
100 *
101 * @param message The detail message.
102 * @param e The exception to be wrapped in a SAXException.
103 */
104 public SAXException(String message, Exception e) {
105 super (message);
106 this .exception = e;
107 }
108
109 /**
110 * Return a detail message for this exception.
111 *
112 * <p>If there is an embedded exception, and if the SAXException
113 * has no detail message of its own, this method will return
114 * the detail message from the embedded exception.</p>
115 *
116 * @return The error or warning message.
117 */
118 public String getMessage() {
119 String message = super .getMessage();
120
121 if (message == null && exception != null) {
122 return exception.getMessage();
123 } else {
124 return message;
125 }
126 }
127
128 /**
129 * Return the embedded exception, if any.
130 *
131 * @return The embedded exception, or null if there is none.
132 */
133 public Exception getException() {
134 return exception;
135 }
136
137 /**
138 * Override toString to pick up any embedded exception.
139 *
140 * @return A string representation of this exception.
141 */
142 public String toString() {
143 if (exception != null) {
144 return exception.toString();
145 } else {
146 return super .toString();
147 }
148 }
149
150 //////////////////////////////////////////////////////////////////////
151 // Internal state.
152 //////////////////////////////////////////////////////////////////////
153
154 /**
155 * @serial The embedded exception if tunnelling, or null.
156 */
157 private Exception exception;
158
159 // Added serialVersionUID to preserve binary compatibility
160 static final long serialVersionUID = 583241635256073760L;
161 }
162
163 // end of SAXException.java
|