====== e.tostring_e.getmessage_e.printstacktrace_의_차이점 ====== * description : * author : 도봉산핵주먹 * email : hylee@repia.com * lastupdate : 2020-04-23 ===== 작성 이유 ===== * 내부 프로젝트들을 진행하면서 에러로그가 중요하단걸 느꼈습니다. * 에러 로그를 잘 보려면 예외가 발생할 곳에 'try{} catch(){}'를 잘 써야됩니다. * 'catch(Excaption e)'에 'Excaptio e'의 에러내용을 잘 출력해서 봐야됩니다. ===== Excqption e 메세지 기능 ===== * e.getMessage() : 에러 이벤트와 함께 들어오는 메세지 출력 * e.toString() : 에러 이벤트의 toString()을 호출해서 간단한 에러 메시지 확인 * e.printStackTrace() : 에러 메세지의 발생 근원지를 찾아 단계별로 에러 출력 ===== Java 예제 ===== 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()); e.printStackTrace(); return; } } } e.getMessage() = 에러내용입니다. e.toString() = java.lang.Exception: 에러내용입니다. e.printStackTrace() = java.lang.Exception: 에러내용입니다. at ExeThrowException.main(ExeThrowException.java:5) ===== Ref ===== * [[https://passionha.tistory.com/146|e.toString(), e.getMessage(), e.printStackTrace()의 차이점]] {{tag>도봉산핵주먹 예외처리 e.printStackTrace() e.getMessage() e.toString()}}