Java Throwable to String stackTrace(Throwable e)

Here you can find the source of stackTrace(Throwable e)

Description

stack Trace

License

Open Source License

Declaration

public static String stackTrace(Throwable e) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Pivotal Software, Inc. and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:/*from   w  w w. j  a v a 2s  . c  o m*/
 *     Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Main {
    public static String stackTrace(Throwable e) {
        try {
            ByteArrayOutputStream trace = new ByteArrayOutputStream();
            PrintStream dump = new PrintStream(trace, true, "utf8");
            e.printStackTrace(dump);
            return trace.toString("utf8");
        } catch (Exception shouldNotHappen) {
            throw new RuntimeException(shouldNotHappen);
        }
    }
}

Related

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