gwooden_코린이
java_예외처리02 배열_221130(8일차) 본문
728x90
package 예외처리;
public class ExceptionEx2 {
public static void main(String[] args) {
try {
int[] arr = {1, 2, 3};
System.out.println(arr[3]); //문맥상 이상이 없지만 배열방은 위에서 3가지로 되어있어 arr[2]가 맞는것
System.out.println(3/0);
Integer.parseInt("a"); //괄호안에 넣어준것들을 정수로 바꿔주는 메서드
} catch (ArithmeticException e) {
System.out.println("0으로 나눌수 없다");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("인덱스 범위 초과");
} catch (Exception e) {
System.out.println("예외 발생");
}
}
}
package 예외처리;
public class ExceptionEx2 {
public static void main(String[] args) {
try {
int[] arr = {1, 2, 3};
// System.out.println(arr[3]); //문맥상 이상이 없지만 배열방은 위에서 3가지로 되어있어 arr[2]가 맞는것
System.out.println(3/0);
Integer.parseInt("a"); //괄호안에 넣어준것들을 정수로 바꿔주는 메서드
} catch (ArithmeticException e) {
System.out.println("0으로 나눌수 없다");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("인덱스 범위 초과");
} catch (Exception e) {
System.out.println("예외 발생");
}
}
}
package 예외처리;
public class ExceptionEx2 {
public static void main(String[] args) {
try {
int[] arr = {1, 2, 3};
// System.out.println(arr[3]); //문맥상 이상이 없지만 배열방은 위에서 3가지로 되어있어 arr[2]가 맞는것
// System.out.println(3/0);
Integer.parseInt("a"); //괄호안에 넣어준것들을 정수로 바꿔주는 메서드
} catch (ArithmeticException e) {
System.out.println("0으로 나눌수 없다");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("인덱스 범위 초과");
} catch (Exception e) {
System.out.println("예외 발생");
}
}
}
728x90
'java > 8일차' 카테고리의 다른 글
java_예외 강제 발생_221130(8일차) (0) | 2022.11.30 |
---|---|
java_예외처리 부수적인 경우_221130(8일차) (0) | 2022.11.30 |
java_예외처리_221130(8일차) (0) | 2022.11.30 |
java_내부인터페이스_221130(8일차) (0) | 2022.11.30 |
java_내부클래스_221130(8일차) (0) | 2022.11.30 |
Comments