Here you can find the source of printStackTrace(PrintStream ps, Exception e)
public static void printStackTrace(PrintStream ps, Exception e)
//package com.java2s; import java.io.*; public class Main { public static void printStackTrace(PrintStream ps, Exception e) { if (e == null) print(ps, getStackTrace());/*from w w w.ja v a 2 s . com*/ else print(ps, stackTraceToString(e.getStackTrace())); } public static void printStackTrace(PrintStream ps) { printStackTrace(ps, null); } public static void printStackTrace() { System.out.print(getStackTrace()); } public static void print(PrintStream ps, String buf) { System.out.print(buf); if (ps != null) { ps.print(buf); } } public static String getStackTrace() { Thread t = Thread.currentThread(); // FMStackTrace fst = new FMStackTrace(t.getStackTrace()); // return fst.toString(); StackTraceElement[] ste = t.getStackTrace(); return stackTraceToString(ste); } public static String stackTraceToString(StackTraceElement[] ste) { String str = ""; for (int i = 0; i < ste.length; i++) { str += String.format(" [%02d] %s \n", i, ste[i].toString()); } return str; } }