KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > parser > ParseException


1 /*
2
3    Copyright 2000 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.parser;
19
20 /**
21  * This class encapsulates a general parse error or warning.
22  *
23  * <p>This class can contain basic error or warning information from
24  * either the parser or the application.
25  *
26  * <p>If the application needs to pass through other types of
27  * exceptions, it must wrap those exceptions in a ParseException.
28  *
29  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
30  * @version $Id: ParseException.java,v 1.3 2004/08/18 07:14:47 vhardy Exp $
31  */

32 public class ParseException extends RuntimeException JavaDoc {
33     /**
34      * @serial The embedded exception if tunnelling, or null.
35      */

36     protected Exception JavaDoc exception;
37     
38     /**
39      * @serial The line number.
40      */

41     protected int lineNumber;
42
43     /**
44      * @serial The column number.
45      */

46     protected int columnNumber;
47
48     /**
49      * Creates a new ParseException.
50      * @param message The error or warning message.
51      * @param line The line of the last parsed character.
52      * @param column The column of the last parsed character.
53      */

54     public ParseException (String JavaDoc message, int line, int column) {
55     super(message);
56     exception = null;
57     lineNumber = line;
58     columnNumber = column;
59     }
60     
61     /**
62      * Creates a new ParseException wrapping an existing exception.
63      *
64      * <p>The existing exception will be embedded in the new
65      * one, and its message will become the default message for
66      * the ParseException.
67      * @param e The exception to be wrapped in a ParseException.
68      */

69     public ParseException (Exception JavaDoc e) {
70     exception = e;
71     lineNumber = -1;
72     columnNumber = -1;
73     }
74     
75     /**
76      * Creates a new ParseException from an existing exception.
77      *
78      * <p>The existing exception will be embedded in the new
79      * one, but the new exception will have its own message.
80      * @param message The detail message.
81      * @param e The exception to be wrapped in a SAXException.
82      */

83     public ParseException (String JavaDoc message, Exception JavaDoc e) {
84     super(message);
85     this.exception = e;
86     }
87     
88     /**
89      * Return a detail message for this exception.
90      *
91      * <p>If there is a embedded exception, and if the ParseException
92      * has no detail message of its own, this method will return
93      * the detail message from the embedded exception.
94      * @return The error or warning message.
95      */

96     public String JavaDoc getMessage () {
97     String JavaDoc message = super.getMessage();
98     
99     if (message == null && exception != null) {
100         return exception.getMessage();
101     } else {
102         return message;
103     }
104     }
105     
106     /**
107      * Return the embedded exception, if any.
108      * @return The embedded exception, or null if there is none.
109      */

110     public Exception JavaDoc getException () {
111     return exception;
112     }
113
114     /**
115      * Returns the line of the last parsed character.
116      */

117     public int getLineNumber() {
118     return lineNumber;
119     }
120
121     /**
122      * Returns the column of the last parsed character.
123      */

124     public int getColumnNumber() {
125     return columnNumber;
126     }
127 }
128
Popular Tags