Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/SAXException.java
48534 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// SAX exception class.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: SAXException.java,v 1.3 2004/11/03 22:55:32 jsuttor Exp $2930package org.xml.sax;3132/**33* Encapsulate a general SAX error or warning.34*35* <blockquote>36* <em>This module, both source code and documentation, is in the37* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>38* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>39* for further information.40* </blockquote>41*42* <p>This class can contain basic error or warning information from43* either the XML parser or the application: a parser writer or44* application writer can subclass it to provide additional45* functionality. SAX handlers may throw this exception or46* any exception subclassed from it.</p>47*48* <p>If the application needs to pass through other types of49* exceptions, it must wrap those exceptions in a SAXException50* or an exception derived from a SAXException.</p>51*52* <p>If the parser or application needs to include information about a53* specific location in an XML document, it should use the54* {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>55*56* @since SAX 1.057* @author David Megginson58* @version 2.0.1 (sax2r2)59* @see org.xml.sax.SAXParseException60*/61public class SAXException extends Exception {626364/**65* Create a new SAXException.66*/67public SAXException ()68{69super();70this.exception = null;71}727374/**75* Create a new SAXException.76*77* @param message The error or warning message.78*/79public SAXException (String message) {80super(message);81this.exception = null;82}838485/**86* Create a new SAXException wrapping an existing exception.87*88* <p>The existing exception will be embedded in the new89* one, and its message will become the default message for90* the SAXException.</p>91*92* @param e The exception to be wrapped in a SAXException.93*/94public SAXException (Exception e)95{96super();97this.exception = e;98}99100101/**102* Create a new SAXException from an existing exception.103*104* <p>The existing exception will be embedded in the new105* 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*/110public SAXException (String message, Exception e)111{112super(message);113this.exception = e;114}115116117/**118* Return a detail message for this exception.119*120* <p>If there is an embedded exception, and if the SAXException121* has no detail message of its own, this method will return122* the detail message from the embedded exception.</p>123*124* @return The error or warning message.125*/126public String getMessage ()127{128String message = super.getMessage();129130if (message == null && exception != null) {131return exception.getMessage();132} else {133return message;134}135}136137138/**139* Return the embedded exception, if any.140*141* @return The embedded exception, or null if there is none.142*/143public Exception getException ()144{145return exception;146}147148/**149* Return the cause of the exception150*151* @return Return the cause of the exception152*/153public Throwable getCause() {154return exception;155}156157/**158* Override toString to pick up any embedded exception.159*160* @return A string representation of this exception.161*/162public String toString ()163{164if (exception != null) {165return super.toString() + "\n" + exception.toString();166} else {167return super.toString();168}169}170171172173//////////////////////////////////////////////////////////////////////174// Internal state.175//////////////////////////////////////////////////////////////////////176177178/**179* @serial The embedded exception if tunnelling, or null.180*/181private Exception exception;182183// Added serialVersionUID to preserve binary compatibility184static final long serialVersionUID = 583241635256073760L;185}186187// end of SAXException.java188189190