Java Throwable to String getStackTrace(final Throwable e)

Here you can find the source of getStackTrace(final Throwable e)

Description

Gets the stack trace of exception as string

License

Open Source License

Declaration

public static String getStackTrace(final Throwable e) 

Method Source Code


//package com.java2s;
/*//from w w w . j  a va  2s .c  o  m
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    /**
     * Gets the stack trace of exception as string
     */
    public static String getStackTrace(final Throwable e) {
        final StringWriter s = new StringWriter();
        e.printStackTrace(new PrintWriter(s));
        return s.toString();
    }

    public static String toString(final boolean[] array) {
        String result = "[";
        for (int i = 0; i < array.length; i++) {
            if (i > 0) {
                result += ", ";
            }
            result += array[i];
        }

        return result + "]";
    }

    public static String toString(final int[] array) {
        String result = "[";
        for (int i = 0; i < array.length; i++) {
            if (i > 0) {
                result += ", ";
            }
            result += array[i];
        }

        return result + "]";
    }
}

Related

  1. getExceptionText(Throwable e)
  2. getExceptionTrace(Throwable e)
  3. getStackTrace (final Throwable e)
  4. getStackTrace(@Nonnull final Throwable throwable)
  5. getStackTrace(final Throwable aThrowable)
  6. getStackTrace(final Throwable error)
  7. getStackTrace(final Throwable exception)
  8. getStackTrace(final Throwable t)
  9. getStackTrace(final Throwable t)