/**

     * e.printStackTrace(); 실행결과를 System.out 객체가 아닌 String 객체에 저장하여 반환

     * @param e 예외클래스 객체

     * @return

     */

    public String printStackTraceToString(Throwable e) {

        StringBuffer sb = new StringBuffer();

 

        try {

            sb.append(e.toString());

            sb.append("\n");

            StackTraceElement element[] = e.getStackTrace();

            for (int idx = 0; idx < element.length; idx++) {

                sb.append("\tat ");

                sb.append(element[idx].toString());

                sb.append("\n");

            }

        } catch (Exception ex) {

            return e.toString();

        }

 

        return sb.toString();

    }



[출처]http://blog.naver.com/ddak2ya/30151431652

Posted by MR 손
,