Here you can find the source of getStackTraceAsString(Throwable t)
public static String getStackTraceAsString(Throwable t)
//package com.java2s; /******************************************************************************* * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Apache License v2.0 which accompany this distribution. * * The Apache License is available at//from w ww .j a v a2 s. c om * http://www.apache.org/licenses/LICENSE-2.0 * *******************************************************************************/ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; public class Main { public static final String EMPTY_STRING = ""; public static String getStackTraceAsString(Throwable t) { if (t != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); final String stackTraceAsString = sw.toString(); try { sw.close(); } catch (IOException e) { e.printStackTrace(); } pw.close(); return stackTraceAsString; } else { return EMPTY_STRING; } } }