Here you can find the source of printStackTrace(String msg, Throwable throwable)
public static void printStackTrace(String msg, Throwable throwable)
//package com.java2s; //License from project: Apache License public class Main { public static void printStackTrace(String msg, Throwable throwable) { StringBuilder str = new StringBuilder( throwable.getClass().getName() + " : " + throwable.getMessage() + "(" + msg + ")\n"); str.append(stackTrace(throwable.getStackTrace())); System.err.println(str.toString()); Throwable cause = throwable.getCause(); if (cause != null) { printStackTrace(cause.getMessage(), cause); }//from w w w . j a v a 2 s .co m } public static void printStackTrace(String msg, StackTraceElement[] stackTrace) { StringBuilder str = new StringBuilder(msg + "\n"); str.append(stackTrace(stackTrace)); System.err.println(str.toString()); str = null; } public static void printStackTrace(String msg) { System.err.println(msg); } public static String stackTrace(StackTraceElement[] stackTrace) { StringBuilder str = new StringBuilder(""); for (StackTraceElement s : stackTrace) { str.append("\t").append(s.getClassName() + "." + s.getMethodName() + "(" + s.getFileName() + ":" + s.getLineNumber() + ")" + "\n"); } return str.toString(); } public static String stackTrace(String msg, Throwable throwable) { StringBuilder str = new StringBuilder(throwable.getMessage() + " : " + msg + "\n"); str.append(stackTrace(throwable.getStackTrace())); return str.toString(); } }