Here you can find the source of stacktrace()
public static String stacktrace()
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w .j ava2 s .c om * @return a String showing the current stack */ public static String stacktrace() { try { throw new Exception(); } catch (Exception e) { StackTraceElement[] trace = e.getStackTrace(); StringBuilder sb = new StringBuilder(); for (int i = 1; i < trace.length; i++) { StackTraceElement stackTraceElement = trace[i]; sb.append(stackTraceElement.toString()); sb.append('\n'); } return sb.toString(); } } }