1 // SAX exception class. 2 // http://www.saxproject.org 3 // No warranty; no copyright -- use this as you will. 4 // $Id: SAXException.java,v 1.7 2002/01/30 21:13:48 dbrownell Exp $ 5 6 package org.xml.sax; 7 8 import android.compat.annotation.UnsupportedAppUsage; 9 10 /** 11 * Encapsulate a general SAX error or warning. 12 * 13 * <blockquote> 14 * <em>This module, both source code and documentation, is in the 15 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> 16 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a> 17 * for further information. 18 * </blockquote> 19 * 20 * <p>This class can contain basic error or warning information from 21 * either the XML parser or the application: a parser writer or 22 * application writer can subclass it to provide additional 23 * functionality. SAX handlers may throw this exception or 24 * any exception subclassed from it.</p> 25 * 26 * <p>If the application needs to pass through other types of 27 * exceptions, it must wrap those exceptions in a SAXException 28 * or an exception derived from a SAXException.</p> 29 * 30 * <p>If the parser or application needs to include information about a 31 * specific location in an XML document, it should use the 32 * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p> 33 * 34 * @since SAX 1.0 35 * @author David Megginson 36 * @version 2.0.1 (sax2r2) 37 * @see org.xml.sax.SAXParseException 38 */ 39 public class SAXException extends Exception { 40 41 42 /** 43 * Create a new SAXException. 44 */ SAXException()45 public SAXException () 46 { 47 this.exception = null; 48 } 49 50 51 /** 52 * Create a new SAXException. 53 * 54 * @param message The error or warning message. 55 */ SAXException(String message)56 public SAXException (String message) { 57 super(message); 58 this.exception = null; 59 } 60 61 62 /** 63 * Create a new SAXException wrapping an existing exception. 64 * 65 * <p>The existing exception will be embedded in the new 66 * one, and its message will become the default message for 67 * the SAXException.</p> 68 * 69 * @param e The exception to be wrapped in a SAXException. 70 */ SAXException(Exception e)71 public SAXException (Exception e) 72 { 73 this.exception = e; 74 } 75 76 77 /** 78 * Create a new SAXException from an existing exception. 79 * 80 * <p>The existing exception will be embedded in the new 81 * one, but the new exception will have its own message.</p> 82 * 83 * @param message The detail message. 84 * @param e The exception to be wrapped in a SAXException. 85 */ SAXException(String message, Exception e)86 public SAXException (String message, Exception e) 87 { 88 super(message); 89 this.exception = e; 90 } 91 92 93 /** 94 * Return a detail message for this exception. 95 * 96 * <p>If there is an embedded exception, and if the SAXException 97 * has no detail message of its own, this method will return 98 * the detail message from the embedded exception.</p> 99 * 100 * @return The error or warning message. 101 */ getMessage()102 public String getMessage () 103 { 104 String message = super.getMessage(); 105 106 if (message == null && exception != null) { 107 return exception.getMessage(); 108 } else { 109 return message; 110 } 111 } 112 113 114 /** 115 * Return the embedded exception, if any. 116 * 117 * @return The embedded exception, or null if there is none. 118 */ getException()119 public Exception getException () 120 { 121 return exception; 122 } 123 124 125 /** 126 * Override toString to pick up any embedded exception. 127 * 128 * @return A string representation of this exception. 129 */ toString()130 public String toString () 131 { 132 if (exception != null) { 133 return exception.toString(); 134 } else { 135 return super.toString(); 136 } 137 } 138 139 140 141 ////////////////////////////////////////////////////////////////////// 142 // Internal state. 143 ////////////////////////////////////////////////////////////////////// 144 145 146 /** 147 * @serial The embedded exception if tunnelling, or null. 148 */ 149 @UnsupportedAppUsage 150 private Exception exception; 151 152 } 153 154 // end of SAXException.java 155