1 /* XMLParseException.java NanoXML/Lite
2 *
3 * This file is part of NanoXML 2 Lite.
4 * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
5 *
6 * This software is provided 'as-is', without any express or implied warranty.
7 * In no event will the authors be held liable for any damages arising from the
8 * use of this software.
9 *
10 * Permission is granted to anyone to use this software for any purpose,
11 * including commercial applications, and to alter it and redistribute it
12 * freely, subject to the following restrictions:
13 *
14 * 1. The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software in
16 * a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24
25
26 package nanoxml;
27
28
29 /**
30 * An XMLParseException is thrown when an error occures while parsing an XML
31 * string.
32 * <P>
33 * @see nanoxml.XMLElement
34 *
35 * @author Marc De Scheemaecker
36 */
37 public class XMLParseException
38 extends RuntimeException
39 {
40
41 /**
42 * Indicates that no line number has been associated with this exception.
43 */
44 public static final int NO_LINE = -1;
45
46
47 /**
48 * The line number in the source code where the error occurred, or
49 * <code>NO_LINE</code> if the line number is unknown.
50 *
51 * <dl><dt><b>Invariants:</b></dt><dd>
52 * <ul><li><code>lineNr > 0 || lineNr == NO_LINE</code>
53 * </ul></dd></dl>
54 */
55 private int lineNr;
56
57
58 /**
59 * Creates an exception.
60 *
61 * @param name The name of the element where the error is located.
62 * @param message A message describing what went wrong.
63 *
64 * </dl><dl><dt><b>Preconditions:</b></dt><dd>
65 * <ul><li><code>message != null</code>
66 * </ul></dd></dl>
67 *
68 * <dl><dt><b>Postconditions:</b></dt><dd>
69 * <ul><li>getLineNr() => NO_LINE
70 * </ul></dd></dl><dl>
71 */
72 public XMLParseException(String name,
73 String message)
74 {
75 super("XML Parse Exception during parsing of "
76 + ((name == null) ? "the XML definition"
77 : ("a " + name + " element"))
78 + ": " + message);
79
80 this.lineNr = XMLParseException.NO_LINE;
81 }
82
83
84 /**
85 * Creates an exception.
86 *
87 * @param name The name of the element where the error is located.
88 * @param lineNr The number of the line in the input.
89 * @param message A message describing what went wrong.
90 *
91 * </dl><dl><dt><b>Preconditions:</b></dt><dd>
92 * <ul><li><code>message != null</code>
93 * <li><code>lineNr > 0</code>
94 * </ul></dd></dl>
95 *
96 * <dl><dt><b>Postconditions:</b></dt><dd>
97 * <ul><li>getLineNr() => lineNr
98 * </ul></dd></dl><dl>
99 */
100 public XMLParseException(String name,
101 int lineNr,
102 String message)
103 {
104 super("XML Parse Exception during parsing of "
105 + ((name == null) ? "the XML definition"
106 : ("a " + name + " element"))
107 + " at line " + lineNr + ": " + message);
108
109 this.lineNr = lineNr;
110 }
111
112
113 /**
114 * Where the error occurred, or <code>NO_LINE</code> if the line number is
115 * unknown.
116 *
117 * @see nanoxml.XMLParseException#NO_LINE
118 */
119 public int getLineNr()
120 {
121 return this.lineNr;
122 }
123
124 }