show Call Stack via StackTraceElement - Java java.lang

Java examples for java.lang:Throwable

Description

show Call Stack via StackTraceElement

Demo Code


//package com.java2s;

public class Main {
    public static void showCallStack() {
        StackTraceElement[] stackTraceElements = Thread.currentThread()
                .getStackTrace();/*ww  w .  j  ava2  s.c o  m*/
        System.out
                .println("##############################################");
        for (int i = 2; i < stackTraceElements.length; i++) {
            StackTraceElement ste = stackTraceElements[i];
            String classname = ste.getClassName();
            String methodName = ste.getMethodName();
            int lineNumber = ste.getLineNumber();
            System.out.println(classname + "." + methodName + ":"
                    + lineNumber);
        }
    }
}

Related Tutorials