You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/08/01 22:15:43 UTC
cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
bayard 2002/08/01 13:15:43
Modified: lang/src/java/org/apache/commons/lang StringUtils.java
Log:
Added a stackTrace method. Possibly needs renaming. It's in common use in
other Jakarta projects such as Ant. Turns a Throwable into a String.
Revision Changes Path
1.6 +15 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
Index: StringUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StringUtils.java 26 Jul 2002 01:40:11 -0000 1.5
+++ StringUtils.java 1 Aug 2002 20:15:43 -0000 1.6
@@ -60,6 +60,7 @@
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -1565,6 +1566,19 @@
// Step 7
return d[n][m];
}
+
+ /**
+ * Convenient method to retrieve the full stacktrace from a given exception. * @param t the exception to get the stacktrace from.
+ * @return the stacktrace from the given exception.
+ */
+ public static String getStackTrace(Throwable t) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw, true);
+ t.printStackTrace(pw);
+ pw.flush();
+ pw.close();
+ return sw.toString();
+ }
// these are not really of use in the Java world. Only if you're a C afficionado
// public static String sprintf(String format, Object[] list);
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
Posted by Daniel Rall <dl...@finemaltcoding.com>.
This code is in use in the decompose() method of the
org.apache.commons.lang.exception.NestableDelegate class. It would
makes sense if NestableDelegate could find a way to use this new
method.
This method would also make more sense in a new class, ThrowableUtils,
with a signature like toStackTrace(Throwable). Wrapping a
toStrackTraceBuffer(Throwable) : StringBuffer method might make sense
as well.
- Dan
bayard@apache.org writes:
> bayard 2002/08/01 13:15:43
>
> Modified: lang/src/java/org/apache/commons/lang StringUtils.java
> Log:
> Added a stackTrace method. Possibly needs renaming. It's in common use in
> other Jakarta projects such as Ant. Turns a Throwable into a String.
>
> Revision Changes Path
> 1.6 +15 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
>
> Index: StringUtils.java
> ===================================================================
> RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -u -r1.5 -r1.6
> --- StringUtils.java 26 Jul 2002 01:40:11 -0000 1.5
> +++ StringUtils.java 1 Aug 2002 20:15:43 -0000 1.6
> @@ -60,6 +60,7 @@
> import java.io.OutputStreamWriter;
> import java.io.OutputStream;
> import java.io.PrintWriter;
> +import java.io.StringWriter;
> import java.io.IOException;
> import java.util.NoSuchElementException;
> import java.util.StringTokenizer;
> @@ -1565,6 +1566,19 @@
> // Step 7
> return d[n][m];
> }
> +
> + /**
> + * Convenient method to retrieve the full stacktrace from a given exception. * @param t the exception to get the stacktrace from.
> + * @return the stacktrace from the given exception.
> + */
> + public static String getStackTrace(Throwable t) {
> + StringWriter sw = new StringWriter();
> + PrintWriter pw = new PrintWriter(sw, true);
> + t.printStackTrace(pw);
> + pw.flush();
> + pw.close();
> + return sw.toString();
> + }
>
> // these are not really of use in the Java world. Only if you're a C afficionado
> // public static String sprintf(String format, Object[] list);
--
Daniel Rall <dl...@finemaltcoding.com>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>