Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created May 14, 2021 09:44
Show Gist options
  • Save ParadoxV5/5c9b904ff1e7a4e8127a166bef169ab6 to your computer and use it in GitHub Desktop.
Save ParadoxV5/5c9b904ff1e7a4e8127a166bef169ab6 to your computer and use it in GitHub Desktop.
String form of `Throwable#getStackTrace()`
import java.io.PrintWriter;
/** Wrapper class for {@link #of()} */
public final class GetStackTraceString {
/**
@param e the {@link Throwable}
@return
a {@link String} form of this {@code Throwable}’s {@link Throwable#getStackTrace() stack trace}
using {@link Throwable#printStackTrace(PrintWriter)}
*/
public static String of(Throwable e) {
java.io.StringWriter stringWriter = new java.io.StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment