예제코드
ppackage ch08exception;
public class MyExeption03 {
public static void main(String[] args) {
String xx = "aa";
first(xx);
}
private static void first(String xx) {
second();
int x = Integer.parseInt(xx);
}
private static void second() {
third();
}
private static void third() {
int i = 1, j = 0;
System.out.println(i / j);
}
}
콘솔창 출력:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at ch08exception.MyExeption03.third(MyExeption03.java:20)
at ch08exception.MyExeption03.second(MyExeption03.java:15)
at ch08exception.MyExeption03.first(MyExeption03.java:10)
at ch08exception.MyExeption03.main(MyExeption03.java:6)
예외 발생 상위스택 찾는법.
- "호출"은 컴퓨터 메모리에 "생성"된다는 뜻.
- 생성과 소멸은 LIFO방식이다.
- 위의 코드를 예로 들면,
- Main -> first -> second -> third순으로 생성되고,
- third -> second -> first -> Main순으로 소멸한다.
- 생성과 소멸은 LIFO방식이다.
- 호출하는 자를 상위스택, 호출받는 자를 하위스택이라 한다.
- 자바는 오류가 났을 때 콘솔창에 최상위층이 오류메시지의 맨 아래에 위치한다.