Here you can find the source of dumpStackTrace(int depth)
private static String dumpStackTrace(int depth)
//package com.java2s; //License from project: Apache License import java.io.PrintWriter; import java.io.StringWriter; public class Main { private static String dumpStackTrace(int depth) { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (int i = 0; i < stackTrace.length && i < depth; i++) { StackTraceElement se = stackTrace[i]; sb.append(" - " + se.getClassName() + "#" + se.getMethodName() + ":" + se.getLineNumber() + "\n"); }//from w w w . ja v a2 s . com return sb.toString(); } public static String getStackTrace(Throwable t) { StringWriter out = new StringWriter(); t.printStackTrace(new PrintWriter(out)); return out.toString(); } }