Created
May 14, 2021 09:44
-
-
Save ParadoxV5/5c9b904ff1e7a4e8127a166bef169ab6 to your computer and use it in GitHub Desktop.
String form of `Throwable#getStackTrace()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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