Here you can find the source of stackTrace()
public static final String stackTrace()
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*www . j a v a 2 s. c o m*/ * Returns a stack trace of the current threads * @return String */ public static final String stackTrace() { return stackTrace("Stack Dump"); } /** * Returns a stack trace of the current threads titled with the input * string. * @param str the title of the trace. * @return String */ public static final String stackTrace(String str) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); new Exception(str).printStackTrace(ps); return (baos.toString()); } }