gwooden_코린이

java_예외처리02 배열_221130(8일차) 본문

java/8일차

java_예외처리02 배열_221130(8일차)

gwooden22 2022. 11. 30. 14:55
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
Comments