Author: techfox9

Creating Java Exception getStackTrace() as a string

Monday, December 17th, 2012 @ 3:52 pm

[java]

public class t1 {
public static void main(String[] args) {
final Throwable t = new IllegalArgumentException(“hi!”);

StringBuffer sb = new StringBuffer();
for (int tx = 0 ; tx < t.getStackTrace().length ; tx ++ ) { sb.append(t.getStackTrace()[tx] ); sb.append("\n"); } System.out.println(sb); } } [/java] or, simpler: [java] System.out.println("STACK: [[" + java.util.Arrays.toString(Thread.currentThread().getStackTrace() ).replace(",", "\n") + "]]" ); [/java] . . .

Java, language


 


Comments are closed.