1 /*
2 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 // SAX exception class.
27 // http://www.saxproject.org
28 // No warranty; no copyright -- use this as you will.
29 // $Id: SAXException.java,v 1.3 2004/11/03 22:55:32 jsuttor Exp $
30
31 package org.xml.sax;
32
33 /**
34 * Encapsulate a general SAX error or warning.
35 *
36 * <blockquote>
37 * <em>This module, both source code and documentation, is in the
38 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
39 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
40 * for further information.
41 * </blockquote>
42 *
43 * <p>This class can contain basic error or warning information from
44 * either the XML parser or the application: a parser writer or
45 * application writer can subclass it to provide additional
46 * functionality. SAX handlers may throw this exception or
47 * any exception subclassed from it.</p>
48 *
49 * <p>If the application needs to pass through other types of
50 * exceptions, it must wrap those exceptions in a SAXException
51 * or an exception derived from a SAXException.</p>
52 *
53 * <p>If the parser or application needs to include information about a
54 * specific location in an XML document, it should use the
55 * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
56 *
57 * @since SAX 1.0
58 * @author David Megginson
59 * @see org.xml.sax.SAXParseException
60 */
61 public class SAXException extends Exception {
62
63
64 /**
65 * Create a new SAXException.
66 */
67 public SAXException ()
68 {
69 super();
70 this.exception = null;
71 }
72
73
74 /**
75 * Create a new SAXException.
76 *
77 * @param message The error or warning message.
78 */
79 public SAXException (String message) {
80 super(message);
81 this.exception = null;
82 }
83
84
85 /**
86 * Create a new SAXException wrapping an existing exception.
87 *
88 * <p>The existing exception will be embedded in the new
89 * one, and its message will become the default message for
90 * the SAXException.</p>
91 *
92 * @param e The exception to be wrapped in a SAXException.
93 */
94 public SAXException (Exception e)
95 {
96 super();
97 this.exception = e;
98 }
99
100
101 /**
102 * Create a new SAXException from an existing exception.
103 *
104 * <p>The existing exception will be embedded in the new
105 * one, but the new exception will have its own message.</p>
106 *
107 * @param message The detail message.
108 * @param e The exception to be wrapped in a SAXException.
109 */
110 public SAXException (String message, Exception e)
111 {
112 super(message);
113 this.exception = e;
114 }
115
116
117 /**
118 * Return a detail message for this exception.
119 *
120 * <p>If there is an embedded exception, and if the SAXException
121 * has no detail message of its own, this method will return
122 * the detail message from the embedded exception.</p>
123 *
124 * @return The error or warning message.
125 */
126 public String getMessage ()
127 {
128 String message = super.getMessage();
129
130 if (message == null && exception != null) {
131 return exception.getMessage();
132 } else {
133 return message;
134 }
135 }
136
137
138 /**
139 * Return the embedded exception, if any.
140 *
141 * @return The embedded exception, or null if there is none.
142 */
143 public Exception getException ()
144 {
145 return exception;
146 }
147
148
149 /**
150 * Override toString to pick up any embedded exception.
151 *
152 * @return A string representation of this exception.
153 */
154 public String toString ()
155 {
156 if (exception != null) {
157 return exception.toString();
158 } else {
159 return super.toString();
160 }
161 }
162
163
164
165 //////////////////////////////////////////////////////////////////////
166 // Internal state.
167 //////////////////////////////////////////////////////////////////////
168
169
170 /**
171 * @serial The embedded exception if tunnelling, or null.
172 */
173 private Exception exception;
174
175 // Added serialVersionUID to preserve binary compatibility
176 static final long serialVersionUID = 583241635256073760L;
177 }
178
179 // end of SAXException.java