Java Utililty Methods Stacktrace to String

List of utility methods to do Stacktrace to String

Description

The list of methods to do Stacktrace to String are organized into topic(s).

Method

StringgetStackTraceAsString(Exception e)
get Stack Trace As String
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
String rv = sw.toString();
String[] s = rv.split("\\n", 65);
if (s.length < 65)
...
StringgetStackTraceAsString(Exception e)
get Stack Trace As String
ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(stackTrace);
e.printStackTrace(pw);
pw.close();
return stackTrace.toString();
StringgetStackTraceAsString(String pstrMessage, Exception poException)
Writes out the stack trace into a string and returns it along with the supplied message.
String strMessage = "";
try {
    ByteArrayOutputStream oByteArrayOutputStream = new ByteArrayOutputStream();
    PrintWriter oPrintWriter = new PrintWriter(oByteArrayOutputStream);
    oPrintWriter.println("Exception: " + poException + "\nStack Trace:\n");
    poException.printStackTrace(oPrintWriter);
    oPrintWriter.println("End of Stack Trace");
    strMessage += pstrMessage + " " + oByteArrayOutputStream;
...
StringgetStackTraceFromException(Exception _e)
Creates a String from the stack trace of an exception.
StringWriter sw = new StringWriter();
_e.printStackTrace(new PrintWriter(sw));
return sw.toString();
StringgetStackTraceFromException(Exception e)
get Stack Trace From Exception
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
e.printStackTrace(pw);
pw.flush();
String stackTrace = baos.toString();
return stackTrace;
StringgetStackTraces()
Get a string representation of the current stack state of all the active threads.
StringWriter stringWriter = new StringWriter(5000);
printStackTraces(new PrintWriter(stringWriter));
return stringWriter.toString();
StringgetStackTraceStr(Exception e)
get Stack Trace Str
StringWriter sw = null;
PrintWriter pw = null;
try {
    sw = new StringWriter();
    pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    pw.flush();
    sw.flush();
...
StringgetStackTraceString()
get Stack Trace String
return getStackTraceString(STACK_TRACE_EXCEPTION.fillInStackTrace());
StringgetStackTraceString(Exception e)
Converts the supplied Exception's stack trace to a String.
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteStream);
e.printStackTrace(printStream);
printStream.flush();
String stackTraceString = byteStream.toString();
printStream.close();
return stackTraceString;
StringgetStackTraceString(Exception e)
get Stack Trace String
return getStackTraceString(e, false);