낭만 프로그래머

Exception의 Stack Trace를 String으로 변환 본문

Java/Common

Exception의 Stack Trace를 String으로 변환

조영래 2018. 12. 12. 15:00
import java.io.PrintWriter;
import java.io.StringWriter;

public class PrintStackTrace {

    public static void main(String[] args) {

        try {
            int division = 0 / 0;
        } catch (ArithmeticException e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            String exceptionAsString = sw.toString();
            System.out.println(exceptionAsString);
        }
    }
}


참고 : https://www.programiz.com/java-programming/examples/convert-stack-trace-string