차근차근/JAVA JSP

[ Java ] e.toString(), e.getMessage(), e.printStackTrace()의 차이점

예쁜꽃이피었으면 2014. 7. 26. 01:37

 

http://lusiea.tistory.com/entry/Java-etoString-egetMessage-eprintStackTrace%EC%9D%98-%EC%B0%A8%EC%9D%B4%EC%A0%90

 

 

** 예제
public class ExeThrowException {

   public static void main (String args[]){
      try{
         //메시지와 함께 수동으로 에러 이벤트 발생
         throw new Exception("에러내용입니다.");
      }catch(Exception e){
         System.out.println("e.getMessage() = " + e.getMessage());
         System.out.println("e.toString() = " + e.toString());
         //System.out.println("e.printStackTrace() = " e.printStackTrace());
         e.printStackTrace();
         return;
      }
   }
}

** 결과
e.getMessage() = 에러내용입니다.
e.toString() = java.lang.Exception: 에러내용입니다.
e.printStackTrace() = java.lang.Exception: 에러내용입니다.
              at ExeThrowException.main(ExeThrowException.java:5)


** 기능
e.getMessage() : 에러 이벤트와 함께 들어오는 메세지 출력
e.toString() : 에러 이벤트의 toString()을 호출해서 간단한 에러 메시지 확인
e.printStackTrace() : 에러 메세지의 발생 근원지를 찾아 단계별로 에러 출력

http://wonho0121.tistory.com/entry/egetMessageetoStringeprintStackTrace-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0


e.getMessage()
 = 에러 이벤트와 함께 들어오는 메세지를 출력한다.

e.getMessage(): 출력문구

 

e.toString() = 에러 이벤트의 toString()을 호출해서 간단한 에러 메시지를 확인한다.

e.toString(): java.lang.Exception: 출력문구

 

e.printStackTrace() = 에러 메세지의 발생 근원지를 찾아서 단계별로 에러를 출력한다.

e.printStackTrace(): java.lang.Exception: 출력문구

at ExThrowException.main(ExeThrowException.java:6)

Posted by 김원호


반응형

'차근차근 > JAVA JSP' 카테고리의 다른 글

[Tip] getWriter() 와 getOutputStream() 차이점  (0) 2014.07.26
inputstreamreader  (0) 2014.07.26
마지막 자식 요소를 새로 추가 .append( content, [content] )  (0) 2014.07.26
document.getElementById  (0) 2014.07.26
getInstance()  (0) 2014.07.26