Source code: com/tripi/asp/AspException.java
1 /**
2 * ArrowHead ASP Server
3 * This is a source file for the ArrowHead ASP Server - an 100% Java
4 * VBScript interpreter and ASP server.
5 *
6 * For more information, see http://www.tripi.com/arrowhead
7 *
8 * Copyright (C) 2002 Terence Haddock
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25 package com.tripi.asp;
26
27 /**
28 * Base class of exceptions throws from internal ASP classes.
29 *
30 * @author Terence Haddock
31 * @version 0.9
32 */
33 public class AspException extends Exception
34 {
35 /** Context of this exception */
36 DebugContext ctx = null;
37
38 /** Short description of this exception */
39 String desc;
40
41 /** Number assocated with this error */
42 int errorNumber;
43
44 /**
45 * Constructor with no initial debugging context.
46 * @param desc Short description.
47 */
48 public AspException(String desc)
49 {
50 super(desc);
51 this.desc = desc;
52 this.errorNumber = 1;
53 }
54
55 /**
56 * Constructor with no initial debugging context, and an error number set.
57 * @param desc Short description
58 * @param errorNumber Error number
59 */
60 public AspException(String desc, int errorNumber)
61 {
62 super(desc);
63 this.desc = desc;
64 this.errorNumber = errorNumber;
65 }
66
67 /**
68 * Constructor with the short description of the string, and
69 * the debugging context of the exception.
70 * @param desc Short description.
71 * @param ctx Debugging context.
72 */
73 public AspException(String desc, DebugContext ctx)
74 {
75 super(desc);
76 this.desc = desc;
77 this.ctx = ctx;
78 this.errorNumber = 1;
79 }
80
81 /**
82 * Constructor with the short description of the string, an error number,
83 * and the debugging context of the exception.
84 * @param desc Short description.
85 * @param errorNumber the error number
86 * @param ctx Debugging context.
87 */
88 public AspException(String desc, int errorNumber, DebugContext ctx)
89 {
90 super(desc);
91 this.desc = desc;
92 this.errorNumber = errorNumber;
93 this.ctx = ctx;
94 this.errorNumber = 1;
95 }
96
97 /**
98 * Checks if this exception has its context.
99 * @return <b>true</b> if this exception has its context,
100 * <b>false</b> otherwise.
101 */
102 public boolean hasContext()
103 {
104 return ctx != null;
105 }
106
107 /**
108 * Sets this exception's context.
109 * @param ctx Debugging context
110 */
111 public void setContext(DebugContext ctx)
112 {
113 this.ctx = ctx;
114 }
115
116 /**
117 * Gets this exception's context.
118 * @return Debugging context
119 */
120 public DebugContext getContext()
121 {
122 return ctx;
123 }
124
125 /**
126 * Obtains the short description of this exception.
127 * @return short description of this exception, including
128 * debugging context.
129 */
130 public String toString()
131 {
132 if (ctx != null)
133 {
134 return "File " + ctx.displayFilename + " line " + ctx.lineno +
135 ": " + desc;
136 } else {
137 return "File unknown line unknown: " + desc;
138 }
139 }
140
141 /**
142 * AspCode
143 * @return AspCode of this error
144 */
145 public int AspCode()
146 {
147 // XXX Not really implemented
148 return 1;
149 }
150
151 /**
152 * AspDescription
153 * @return Detailed description of this error
154 */
155 public String AspDescription()
156 {
157 return toString();
158 }
159
160 /**
161 * Description
162 * @return Short Description of this error
163 */
164 public String Description()
165 {
166 return desc;
167 }
168
169 /**
170 * Category
171 * @return Category of this error
172 */
173 public int Category()
174 {
175 /* XXX Not really implemented */
176 return 1;
177 }
178
179 /**
180 * Column
181 * @return Column where this error occured
182 */
183 public int Column()
184 {
185 /* XXX Not really implemented */
186 return 1;
187 }
188
189 /**
190 * File
191 * @return File where this error occured
192 */
193 public String File()
194 {
195 if (ctx == null) return "unknown";
196 return ctx.displayFilename;
197 }
198
199 /**
200 * Line
201 * @return Line number where this error occured
202 */
203 public int Line()
204 {
205 if (ctx == null) return 0;
206 return ctx.lineno;
207 }
208
209 /**
210 * Number
211 * @return COM number of this error
212 */
213 public int Number()
214 {
215 return errorNumber;
216 }
217
218 /**
219 * Source
220 * @return Source where this error occured
221 */
222 public String Source()
223 {
224 /* XXX Not really implemented */
225 return "Source view not implemented.";
226 }
227 }