Java Stacktrace to String stacktrace2string(StackTraceElement[] stackTraceElements)

Here you can find the source of stacktrace2string(StackTraceElement[] stackTraceElements)

Description

stacktracestring

License

Open Source License

Declaration

public static String stacktrace2string(StackTraceElement[] stackTraceElements) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String stacktrace2string(StackTraceElement[] stackTraceElements) {
        StringBuffer stackTraceStringBuffer = new StringBuffer();
        for (StackTraceElement stackTraceElement : stackTraceElements) {
            stackTraceStringBuffer.append(stackTraceElement.toString()).append("\n");
        }//from  www . j a va2s  . c o  m
        return stackTraceStringBuffer.toString();
    }

    public static String stacktrace2string(Throwable x) {
        final Writer result = new StringWriter();
        final PrintWriter printWriter = new PrintWriter(result);
        x.printStackTrace(printWriter);
        return result.toString();
    }
}

Related

  1. getStackTraceString()
  2. getStackTraceString(Exception e)
  3. getStackTraceString(Exception e)
  4. stackTrace()
  5. stacktrace()
  6. stackTraceAsString(Exception ex)
  7. stackTraceContains(String... needles)
  8. stackTraceStr(Exception e)
  9. stackTraceString(Throwable t)