Java Throwable to String stackToString(Throwable throwable, boolean skipMessage)

Here you can find the source of stackToString(Throwable throwable, boolean skipMessage)

Description

Dump message and stack to StringBuffer.

License

Open Source License

Declaration

public static StringBuffer stackToString(Throwable throwable, boolean skipMessage) 

Method Source Code

//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();
    }
}

Related

  1. stackToString(Exception e)
  2. stackToString(Throwable e)
  3. stackToString(Throwable e)
  4. stackToString(Throwable e)
  5. stackToString(Throwable t)
  6. stackTrace(final Throwable t)
  7. stacktrace(Logger logger, Throwable ex)
  8. stackTrace(Throwable cause)
  9. stackTrace(Throwable e)