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. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@136952 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
58503e7eec
commit
477290cb92
|
@ -60,6 +60,7 @@
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -80,7 +81,7 @@
|
||||||
* @author <a href="mailto:ed@apache.org">Ed Korthof</a>
|
* @author <a href="mailto:ed@apache.org">Ed Korthof</a>
|
||||||
* @author <a href="mailto:rand_mcneely@yahoo.com>Rand McNeely</a>
|
* @author <a href="mailto:rand_mcneely@yahoo.com>Rand McNeely</a>
|
||||||
* @author <a href="mailto:scolebourne@joda.org>Stephen Colebourne</a>
|
* @author <a href="mailto:scolebourne@joda.org>Stephen Colebourne</a>
|
||||||
* @version $Id: StringUtils.java,v 1.5 2002/07/26 01:40:11 dlr Exp $
|
* @version $Id: StringUtils.java,v 1.6 2002/08/01 20:15:43 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
|
@ -1566,6 +1567,19 @@ public static int getLevenshteinDistance(String s, String t) {
|
||||||
return d[n][m];
|
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
|
// 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);
|
// public static String sprintf(String format, Object[] list);
|
||||||
// public static Object[] sscanf(String str, String format);
|
// public static Object[] sscanf(String str, String format);
|
||||||
|
|
Loading…
Reference in New Issue