Here you can find the source of getStackTrace(Exception e)
public static String getStackTrace(Exception e)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.StringReader; public class Main { public static String getStackTrace(Exception e) { ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(byteArray, true)); BufferedReader reader = new BufferedReader(new StringReader(byteArray.toString())); String line;//from w w w .j a v a 2 s. com int count = 0; String result = ""; try { while (count++ < 6 && (line = reader.readLine()) != null) { result += line + "\n"; } } catch (Exception ee) { // should never happen ee.printStackTrace(); } return result; } }