Skip to content

Instantly share code, notes, and snippets.

@bluesid
Created February 13, 2024 02:56
Show Gist options
  • Save bluesid/9a8fb0ef7ad8d0a0979086f592aff3f7 to your computer and use it in GitHub Desktop.
Save bluesid/9a8fb0ef7ad8d0a0979086f592aff3f7 to your computer and use it in GitHub Desktop.
Converting a Stack Trace to a String in Java #printStackTrace #JAVA
// https://www.baeldung.com/java-stacktrace-to-string
String stacktrace = ExceptionUtils.getStackTrace(e);
// commons-lang3 jar 구현체
public static String getStackTrace(Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
throwable.printStackTrace(pw);
return sw.getBuffer().toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment