001: /* XMLParseException.java
002: *
003: * $Revision: 1.4 $
004: * $Date: 2002/03/24 10:27:59 $
005: * $Name: RELEASE_2_2_1 $
006: *
007: * This file is part of NanoXML 2 Lite.
008: * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009: *
010: * This software is provided 'as-is', without any express or implied warranty.
011: * In no event will the authors be held liable for any damages arising from the
012: * use of this software.
013: *
014: * Permission is granted to anyone to use this software for any purpose,
015: * including commercial applications, and to alter it and redistribute it
016: * freely, subject to the following restrictions:
017: *
018: * 1. The origin of this software must not be misrepresented; you must not
019: * claim that you wrote the original software. If you use this software in
020: * a product, an acknowledgment in the product documentation would be
021: * appreciated but is not required.
022: *
023: * 2. Altered source versions must be plainly marked as such, and must not be
024: * misrepresented as being the original software.
025: *
026: * 3. This notice may not be removed or altered from any source distribution.
027: *****************************************************************************/
028:
029: package nanoxml;
030:
031: /**
032: * An XMLParseException is thrown when an error occures while parsing an XML
033: * string.
034: * <P>
035: * $Revision: 1.4 $<BR>
036: * $Date: 2002/03/24 10:27:59 $<P>
037: *
038: * @see nanoxml.XMLElement
039: *
040: * @author Marc De Scheemaecker
041: * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
042: */
043: public class XMLParseException extends RuntimeException {
044:
045: /**
046: * Indicates that no line number has been associated with this exception.
047: */
048: public static final int NO_LINE = -1;
049:
050: /**
051: * The line number in the source code where the error occurred, or
052: * <code>NO_LINE</code> if the line number is unknown.
053: *
054: * <dl><dt><b>Invariants:</b></dt><dd>
055: * <ul><li><code>lineNr > 0 || lineNr == NO_LINE</code>
056: * </ul></dd></dl>
057: */
058: private int lineNr;
059:
060: /**
061: * Creates an exception.
062: *
063: * @param name The name of the element where the error is located.
064: * @param message A message describing what went wrong.
065: *
066: * </dl><dl><dt><b>Preconditions:</b></dt><dd>
067: * <ul><li><code>message != null</code>
068: * </ul></dd></dl>
069: *
070: * <dl><dt><b>Postconditions:</b></dt><dd>
071: * <ul><li>getLineNr() => NO_LINE
072: * </ul></dd></dl><dl>
073: */
074: public XMLParseException(String name, String message) {
075: super ("XML Parse Exception during parsing of "
076: + ((name == null) ? "the XML definition"
077: : ("a " + name + " element")) + ": " + message);
078: this .lineNr = XMLParseException.NO_LINE;
079: }
080:
081: /**
082: * Creates an exception.
083: *
084: * @param name The name of the element where the error is located.
085: * @param lineNr The number of the line in the input.
086: * @param message A message describing what went wrong.
087: *
088: * </dl><dl><dt><b>Preconditions:</b></dt><dd>
089: * <ul><li><code>message != null</code>
090: * <li><code>lineNr > 0</code>
091: * </ul></dd></dl>
092: *
093: * <dl><dt><b>Postconditions:</b></dt><dd>
094: * <ul><li>getLineNr() => lineNr
095: * </ul></dd></dl><dl>
096: */
097: public XMLParseException(String name, int lineNr, String message) {
098: super ("XML Parse Exception during parsing of "
099: + ((name == null) ? "the XML definition"
100: : ("a " + name + " element")) + " at line "
101: + lineNr + ": " + message);
102: this .lineNr = lineNr;
103: }
104:
105: /**
106: * Where the error occurred, or <code>NO_LINE</code> if the line number is
107: * unknown.
108: *
109: * @see nanoxml.XMLParseException#NO_LINE
110: */
111: public int getLineNr() {
112: return this.lineNr;
113: }
114:
115: }
|