Here you can find the source of stackToString(Throwable throwable, boolean skipMessage)
public static StringBuffer stackToString(Throwable throwable, boolean skipMessage)
//package com.java2s; /* ******************************************************************* * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. //ww w .j av a 2 s . c o m * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; public class Main { /** Dump message and stack to StringBuffer. */ public static StringBuffer stackToString(Throwable throwable, boolean skipMessage) { if (null == throwable) { return new StringBuffer(); } StringWriter buf = new StringWriter(); PrintWriter writer = new PrintWriter(buf); if (!skipMessage) { writer.println(throwable.getMessage()); } throwable.printStackTrace(writer); try { buf.close(); } catch (IOException ioe) { } // ignored return buf.getBuffer(); } }