Java Dump Stracktrace dumpStack(final PrintStream out, final int skip, final int depth)

Here you can find the source of dumpStack(final PrintStream out, final int skip, final int depth)

Description

dump Stack

License

Open Source License

Declaration

public static void dumpStack(final PrintStream out, final int skip, final int depth) 

Method Source Code


//package com.java2s;
import java.io.PrintStream;

public class Main {
    public static void dumpStack(final PrintStream out) {
        dumpStack(out, 1, -1);//from  w  w  w .java 2  s.c o m
    }

    public static void dumpStack(final PrintStream out, final int skip, final int depth) {
        dumpStack(out, new Exception(""), skip + 1, depth);
    }

    public static void dumpStack(final PrintStream out, final Throwable t, final int skip, final int depth) {
        dumpStack(out, t.getStackTrace(), skip, depth);
    }

    public static void dumpStack(final PrintStream out, final StackTraceElement[] stack, final int skip,
            final int depth) {
        if (null == stack) {
            return;
        }
        final int maxDepth;
        if (0 > depth) {
            maxDepth = stack.length;
        } else {
            maxDepth = Math.min(depth + skip, stack.length);
        }
        for (int i = skip; i < maxDepth; i++) {
            out.println("    [" + i + "]: " + stack[i]);
        }
    }
}

Related

  1. dumpCurrentStackTrace(PrintStream out)
  2. dumpStack()
  3. dumpStack(boolean exit)
  4. dumpStackTrace(int depth)