Here you can find the source of getStackTrace(Exception e)
public static String getStackTrace(Exception e)
//package com.java2s; /*/*from w w w . j av a 2 s . c om*/ * Static String formatting and query routines. * Copyright (C) 2001,2002 Stephen Ostermiller <utils@Ostermiller.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * See COPYING.TXT for details. */ import java.io.StringWriter; import java.io.PrintWriter; public class Main { public static String getStackTrace(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); String ret = sw.toString(); pw.close(); try { sw.close(); } catch (Exception ex) { ex.printStackTrace(); } return ret; } public static String getStackTrace(Throwable e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); String ret = sw.toString(); pw.close(); try { sw.close(); } catch (Exception ex) { ex.printStackTrace(); } return ret; } }