Exception StackTrace to a String

from java 2009/11/24 11:15

Exception이 발생하게 되면 Call Stack에 대한 내용을 저장을 해야 디버깅을 할 수 있다.. 

구글링을 하다보니, Save Exception StackTrace to a String 에서 Exception을 String으로 변환하는 쉬운 예를 보여주고 있네요. 

몇개의 예가 있긴 한데, 아래의 코드가 간결하고 좋네요.. ^^

public static String getException(Exception e )
{
StringWriter w = new StringWriter();
e.printStackTrace(new PrintWriter(w));
return w.toString();
}
Tag // ,