Java Stacktrace to String stackTraceToString(Exception exception)

Here you can find the source of stackTraceToString(Exception exception)

Description

Converts a stack trace of an exception to a string.

License

Open Source License

Declaration

public static String stackTraceToString(Exception exception) 

Method Source Code

//package com.java2s;
/*/*from   w w w  .  ja v  a2  s.  c  om*/
 * JGraLab - The Java Graph Laboratory
 * 
 * Copyright (C) 2006-2010 Institute for Software Technology
 *                         University of Koblenz-Landau, Germany
 *                         ist@uni-koblenz.de
 * 
 * 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 3 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.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Additional permission under GNU GPL version 3 section 7
 * 
 * If you modify this Program, or any covered work, by linking or combining
 * it with Eclipse (or a modified version of that program or an Eclipse
 * plugin), containing parts covered by the terms of the Eclipse Public
 * License (EPL), the licensors of this Program grant you additional
 * permission to convey the resulting work.  Corresponding Source for a
 * non-source form of such a combination shall include the source code for
 * the parts of JGraLab used as well as that of the covered work.
 */

public class Main {
    /**
     * Converts a stack trace of an exception to a string. Used for logging.
     */
    public static String stackTraceToString(Exception exception) {
        String stackTrace = "An exception occured:\n";
        StackTraceElement trace[] = exception.getStackTrace();
        for (StackTraceElement element : trace)
            stackTrace += "@ " + element.toString() + "\n";
        return stackTrace;
    }
}

Related

  1. stackTraceStr(Exception e)
  2. stackTraceString(Throwable t)
  3. stackTraceToString(Exception e)
  4. stackTraceToString(Exception e, int nBack)
  5. stackTraceToString(Exception ex, String message)
  6. stackTraceToString(final StackTraceElement[] stackTrace)
  7. stackTraceToString(final Throwable t, final boolean header, final boolean trim)
  8. stacktraceToString(final Throwable throwable)
  9. stacktraceToString(StackTraceElement[] s)