quintonm 2003/01/02 23:01:35
Modified: src/java/org/apache/turbine/util
TurbineRuntimeException.java
Log:
Now extends NestableRuntimeException from commons-lang
Revision Changes Path
1.3 +6 -140
jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineRuntimeException.java
Index: TurbineRuntimeException.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineRuntimeException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TurbineRuntimeException.java 11 Jul 2002 16:53:21 -0000 1.2
+++ TurbineRuntimeException.java 3 Jan 2003 07:01:35 -0000 1.3
@@ -54,11 +54,7 @@
* <http://www.apache.org/>.
*/
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.LinkedList;
-import java.util.StringTokenizer;
+import org.apache.commons.lang.exception.NestableRuntimeException;
/**
* This is a base class of runtime exeptions thrown by Turbine.
@@ -67,26 +63,19 @@
* {@see java.lang.RuntimeException}). It has the nested stack trace
* functionality found in the {@see TurbineException} class.
*
- * It's sad that this class is a straight copy/paste of Turbine exception.
- * I wish that Java supported NonCheckedException marker interface...
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
*/
-public class TurbineRuntimeException extends RuntimeException
+public class TurbineRuntimeException extends NestableRuntimeException
{
/**
- * Holds the reference to the exception or error that caused
- * this exception to be thrown.
- */
- private Throwable nested = null;
-
- /**
* Constructs a new <code>TurbineRuntimeException</code> without specified
* detail message.
*/
public TurbineRuntimeException()
{
- super();
}
/**
@@ -109,8 +98,7 @@
*/
public TurbineRuntimeException(Throwable nested)
{
- super();
- this.nested = nested;
+ super(nested);
}
/**
@@ -123,129 +111,7 @@
*/
public TurbineRuntimeException(String msg, Throwable nested)
{
- super(msg);
- this.nested = nested;
- }
-
- /**
- * Prints the stack trace of this exception the the standar error
- * stream.
- */
- public void printStackTrace()
- {
- synchronized(System.err)
- {
- printStackTrace(System.err);
- }
- }
-
- /**
- * Prints the stack trace of this exception to the specified print stream.
- *
- * @param out <code>PrintStream</code> to use for output
- */
- public void printStackTrace(PrintStream out)
- {
- synchronized(out)
- {
- PrintWriter pw=new PrintWriter(out, false);
- printStackTrace(pw);
- // flush the PrintWriter before it's GCed
- pw.flush();
- }
- }
-
- /**
- * Prints the stack trace of this exception to the specified print writer.
- *
- * @param out <code>PrintWriter</code> to use for output.
- */
- public void printStackTrace(PrintWriter out)
- {
- synchronized(out)
- {
- printStackTrace(out, 0);
- }
- }
-
- /**
- * Prints the stack trace of this exception skiping a specified number
- * of stack frames.
- *
- * @param out <code>PrintWriter</code> to use for output.
- * @param skip the numbere of stack frames to skip.
- */
- public void printStackTrace(PrintWriter out, int skip)
- {
- String[] st = captureStackTrace();
- if(nested != null)
- {
- if(nested instanceof TurbineRuntimeException)
- {
- ((TurbineRuntimeException)nested).printStackTrace(out, st.length -
2);
- }
- else if(nested instanceof TurbineException)
- {
- ((TurbineException)nested).printStackTrace(out, st.length - 2);
- }
- else
- {
- String[] nst = captureStackTrace(nested);
- for(int i = 0; i<nst.length - st.length + 2; i++)
- {
- out.println(nst[i]);
- }
- }
- out.print("rethrown as ");
- }
- for(int i=0; i<st.length - skip; i++)
- {
- out.println(st[i]);
- }
- }
-
- /**
- * Captures the stack trace associated with this exception.
- *
- * @return an array of Strings describing stack frames.
- */
- private String[] captureStackTrace()
- {
- StringWriter sw = new StringWriter();
- super.printStackTrace(new PrintWriter(sw, true));
- return splitStackTrace(sw.getBuffer().toString());
+ super(msg, nested);
}
- /**
- * Captures the stack trace associated with a <code>Throwable</code>
- * object.
- *
- * @param t the <code>Throwable</code>.
- * @return an array of Strings describing stack frames.
- */
- private String[] captureStackTrace(Throwable t)
- {
- StringWriter sw = new StringWriter();
- t.printStackTrace(new PrintWriter(sw, true));
- return splitStackTrace(sw.getBuffer().toString());
- }
-
- /**
- * Splits the stack trace given as a newline separated string
- * into an array of stack frames.
- *
- * @param stackTrace the stack trace.
- * @return an array of Strings describing stack frames.
- */
- private String[] splitStackTrace(String stackTrace)
- {
- String linebreak = System.getProperty("line.separator");
- StringTokenizer st = new StringTokenizer(stackTrace, linebreak);
- LinkedList list = new LinkedList();
- while(st.hasMoreTokens())
- {
- list.add(st.nextToken());
- }
- return (String [])list.toArray(new String[] {});
- }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>