자바 콘솔 에러 로그(StackTrace), 기본 코드로 흐름 알아보기

ino5·2021년 5월 23일
0
post-thumbnail

소개


예외(Exception)가 발생하여 자바 콘솔에 발생하는 에러 로그(StackTrace)에 대해 기본적인 흐름를 알고자 기본적인 코드를 작성하여 공부해보았습니다.



예제 코드 및 결과


package my.exception;

public class Main {

	static void method1() {
		try {
			method2();
		} catch (Exception e) {
			System.out.print("caused by: ");
			e.printStackTrace();
			throw new RuntimeException();
		}
	}

	static void method2() {
		try {
			method3();
		} catch (Exception e) {
			System.out.print("caused by: ");
			e.printStackTrace();
			throw new NullPointerException();
		}

	}

	static void method3() throws Exception {
		System.out.println(1 / 0);
	}

	public static void main(String[] args) {
		method1();
	}
}



메서드 호출 흐름




에러 발생 순서



각각 Exception에 대한 프린트 흐름






추천글


https://okky.kr/article/338405

StackTrace 읽는 법에 대한 내용으로, 위 글을 강력 추천드립니다.

profile
궁금한 것을 찾아보거나 문제를 해결한 과정을 날 것의 글로 작성하였습니다.

0개의 댓글