Here you can find the source of getStackTrace(Throwable throwable)
public static String getStackTrace(Throwable throwable)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; public class Main { public static String getStackTrace(Throwable throwable) { if (throwable == null) { return "no exception"; } else {//from w ww . j av a2s .co m ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); PrintWriter printwriter = new PrintWriter(new OutputStreamWriter(bytearrayoutputstream)); throwable.printStackTrace(printwriter); printwriter.flush(); printwriter.close(); return bytearrayoutputstream.toString(); } } }