티스토리 뷰

공부

[Java] e.printStackTrace -> String

승가비 2022. 8. 10. 02:35
728x90
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();

https://stackoverflow.com/questions/1149703/how-can-i-convert-a-stack-trace-to-a-string

 

How can I convert a stack trace to a string?

What is the easiest way to convert the result of Throwable.getStackTrace() to a string that depicts the stacktrace?

stackoverflow.com


fun Exception.stackTrace(): String {
    val sw = StringWriter()
    this.printStackTrace(PrintWriter(sw))

    return sw.toString()
}
728x90

'공부' 카테고리의 다른 글

[kotlin] if not in (!in)  (0) 2022.08.11
[kotlin] when(type)  (0) 2022.08.11
[github] actions permissions  (0) 2022.08.10
[JPA] @Query update immediately  (0) 2022.08.10
[pandas] for index, row in rche_df.iterrows():  (0) 2022.08.10
댓글