KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > 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.css.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:13:03 vhardy Exp $
31  */

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

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

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

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

55     public ParseException (String JavaDoc message, int line, int column) {
56     super(message);
57     exception = null;
58     lineNumber = line;
59     columnNumber = column;
60     }
61     
62     /**
63      * Creates a new ParseException 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 ParseException.
68      * @param e The exception to be wrapped in a ParseException.
69      */

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

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

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

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

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

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