Java Stacktrace to String stackTrace()

Here you can find the source of stackTrace()

Description

Returns a stack trace of the current threads

License

Apache License

Return

String

Declaration

public static final String stackTrace() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**/*www  .  j  a v  a  2  s. c  o  m*/
     * Returns a stack trace of the current threads
     * @return String
     */
    public static final String stackTrace() {
        return stackTrace("Stack Dump");
    }

    /**
     * Returns a stack trace of the current threads titled with the input
     * string.
     * @param str the title of the trace.
     * @return String
     */
    public static final String stackTrace(String str) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        new Exception(str).printStackTrace(ps);
        return (baos.toString());
    }
}

Related

  1. getStackTraces()
  2. getStackTraceStr(Exception e)
  3. getStackTraceString()
  4. getStackTraceString(Exception e)
  5. getStackTraceString(Exception e)
  6. stacktrace()
  7. stacktrace2string(StackTraceElement[] stackTraceElements)
  8. stackTraceAsString(Exception ex)
  9. stackTraceContains(String... needles)