Source code: com/tripi/asp/AspNestedException.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 import java.io.PrintStream;
28 import java.io.PrintWriter;
29 import org.apache.log4j.Category;
30
31 /**
32 * AspNestedException handles generic sub-exceptions.
33 *
34 * @author Terence Haddock
35 * @version 0.9
36 */
37 public class AspNestedException extends AspException
38 {
39 /** Debugging category */
40 Category DBG = Category.getInstance(AspNestedException.class);
41
42 /** Nested exception */
43 Throwable nestedEx;
44
45 /**
46 * Constructor with an empty exception.
47 */
48 public AspNestedException()
49 {
50 super(Constants.emptyException.toString());
51 this.nestedEx = Constants.emptyException;
52 }
53
54 /**
55 * Constructor with no initial debugging context
56 * @param ex Nested exception
57 */
58 public AspNestedException(Throwable ex)
59 {
60 super(ex.toString());
61 if (DBG.isDebugEnabled()) DBG.debug("AspNestedException: " + ex.toString());
62 this.nestedEx = ex;
63 }
64
65 /**
66 * Constructor with an error number and no initial debugging context
67 * @param ex Nested exception
68 */
69 public AspNestedException(Throwable ex, int errorNumber)
70 {
71 super(ex.toString(), errorNumber);
72 if (DBG.isDebugEnabled()) DBG.debug("AspNestedException: " + ex.toString());
73 this.nestedEx = ex;
74 }
75
76 /**
77 * Constructor with initial debugging context
78 * @param ex Nested exception
79 * @param ctx Debugging context
80 */
81 public AspNestedException(Throwable ex, DebugContext ctx)
82 {
83 super(ex.toString(), ctx);
84 this.nestedEx = ex;
85 if (nestedEx instanceof AspException)
86 {
87 AspException aspEx = (AspException)nestedEx;
88 if (!aspEx.hasContext())
89 aspEx.setContext(ctx);
90 }
91 }
92
93 /**
94 * Constructor with an error number and initial debugging context
95 * @param ex Nested exception
96 * @param ctx Debugging context
97 */
98 public AspNestedException(Throwable ex, int errorNumber, DebugContext ctx)
99 {
100 super(ex.toString(), errorNumber, ctx);
101 this.nestedEx = ex;
102 if (nestedEx instanceof AspException)
103 {
104 AspException aspEx = (AspException)nestedEx;
105 if (!aspEx.hasContext())
106 aspEx.setContext(ctx);
107 }
108 }
109
110 /**
111 * Set this object's context.
112 */
113 public void setContext(DebugContext ctx)
114 {
115 super.setContext(ctx);
116 if (DBG.isDebugEnabled()) DBG.debug("setContext: " + ctx);
117 if (nestedEx instanceof AspException)
118 {
119 AspException aspEx = (AspException)nestedEx;
120 if (!aspEx.hasContext())
121 aspEx.setContext(ctx);
122 }
123 }
124
125 /**
126 * ToString
127 * @return String representation of exception
128 */
129 public String toString()
130 {
131 if (DBG.isDebugEnabled()) DBG.debug("toString: " + nestedEx.toString());
132 return nestedEx.toString();
133 }
134
135 /**
136 * printStackTrace prints the stack trace to the specified location
137 * @param s PrintStream to use for output
138 */
139 public void printStackTrace(PrintStream s)
140 {
141 if (DBG.isDebugEnabled()) DBG.debug("PrintStackTrace(PrintStream)");
142 nestedEx.printStackTrace(s);
143 s.println(super.toString());
144 }
145
146 /**
147 * printStackTrace prints the stack trace to the specified location
148 * @param s PrintWriter to use for output
149 */
150 public void printStackTrace(PrintWriter s)
151 {
152 if (DBG.isDebugEnabled()) DBG.debug("PrintStackTrace(PrintWriter)");
153 nestedEx.printStackTrace(s);
154 s.println(super.toString());
155 }
156
157 /**
158 * printStackTrace prints the stack trace to System.err
159 */
160 public void printStackTrace()
161 {
162 if (DBG.isDebugEnabled()) DBG.debug("PrintStackTrace(System.err)");
163 nestedEx.printStackTrace();
164 System.err.println(super.toString());
165 }
166
167 /**
168 * AspCode
169 * @return AspCode of this error
170 */
171 public int AspCode()
172 {
173 if (nestedEx instanceof AspException)
174 return ((AspException)nestedEx).AspCode();
175 return super.AspCode();
176 }
177
178 /**
179 * AspDescription
180 * @return Detailed description of this error
181 */
182 public String AspDescription()
183 {
184 if (nestedEx instanceof AspException)
185 return ((AspException)nestedEx).AspDescription();
186 return super.AspDescription();
187 }
188
189 /**
190 * Description
191 * @return Short Description of this error
192 */
193 public String Description()
194 {
195 if (nestedEx instanceof AspException)
196 return ((AspException)nestedEx).Description();
197 return super.Description();
198 }
199
200 /**
201 * Category
202 * @return Category of this error
203 */
204 public int Category()
205 {
206 if (nestedEx instanceof AspException)
207 return ((AspException)nestedEx).Category();
208 return super.Category();
209 }
210
211 /**
212 * Column
213 * @return Column where this error occured
214 */
215 public int Column()
216 {
217 if (nestedEx instanceof AspException)
218 return ((AspException)nestedEx).Column();
219 return super.Column();
220 }
221
222 /**
223 * File
224 * @return File where this error occured
225 */
226 public String File()
227 {
228 if (nestedEx instanceof AspException)
229 return ((AspException)nestedEx).File();
230 return super.File();
231 }
232
233 /**
234 * Line
235 * @return Line number where this error occured
236 */
237 public int Line()
238 {
239 if (nestedEx instanceof AspException)
240 return ((AspException)nestedEx).Line();
241 return super.Line();
242 }
243
244 /**
245 * Number
246 * @return COM number of this error
247 */
248 public int Number()
249 {
250 if (nestedEx instanceof AspException)
251 return ((AspException)nestedEx).Number();
252 return super.Number();
253 }
254
255 /**
256 * Source
257 * @return Source where this error occured
258 */
259 public String Source()
260 {
261 if (nestedEx instanceof AspException)
262 return ((AspException)nestedEx).Source();
263 return super.Source();
264 }
265
266 /**
267 * Clear this exception.
268 */
269 public void Clear()
270 {
271 nestedEx = Constants.emptyException;
272 }
273 }