https://www.youtube.com/watch?v=lSopXBjhBHo
public class ExceptionApp {
public static void main(String[] args) {
System.out.println(1);
int[] scores = {10,20,30};
try {
System.out.println(2);
System.out.println(scores[3]);
System.out.println(3);
// System.out.println(2 / 0);
System.out.println(4);
} catch(ArithmeticException e){
System.out.println("계산이 잘못된 것 같아요.");
} catch(Exception e){
// Exception이 다른예외들의 조상격이라 Exception을 쓰면 포괄적으로 예외를 처리할 수 있음
System.out.println("먼가 이상합니다. 오류가 발생했습니다. ");
}
System.out.println(5);
}
}
먼가 이상합니다. 오류가 발생했습니다.
'생활코딩 > 생활코딩 Java' 카테고리의 다른 글
Java_예외 - checked vs unchecked exception (0) | 2021.10.14 |
---|---|
Java_예외 - e의 비밀 (0) | 2021.10.14 |
Java_예외 - 예외의 처리 (0) | 2021.10.14 |
Java_Interface - 다형성 (0) | 2021.10.14 |
Java_Interface - 인터페이스의 형식 (0) | 2021.10.14 |