Java Dump Stracktrace dumpStackTrace(int depth)

Here you can find the source of dumpStackTrace(int depth)

Description

dump Stack Trace

License

Apache License

Declaration

private static String dumpStackTrace(int depth) 

Method Source Code

//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();
    }
}

Related

  1. dumpCurrentStackTrace(PrintStream out)
  2. dumpStack()
  3. dumpStack(boolean exit)
  4. dumpStack(final PrintStream out, final int skip, final int depth)