본문 바로가기
study/Java

[Java] 26. Exception1 (try, catch)

by 금이패런츠 2022. 3. 22.
728x90
반응형
package chap9;
/*
 * 예외처리 : 발생된 예외를 정상화 하는 방법
 * try catch 구문
 * try 블럭 : 예외 발생 가능성이 있는 구문이 있는 블럭
 * catch 블럭 : try블럭에서 예외 발생시 실행되는 블럭
 */
public class ExceptionEx1 {
	public static void main(String[] args) {
//			System.out.println(args[1]); //ArrayIndexOutOfBoundsException 예외발생
		try {
			System.out.println(10/0);    //ArithmeticException 예외발생
			System.out.println(args[0]); //ArrayIndexOutOfBoundsException 예외발생 => try catch로 예외처리
		} catch(ArrayIndexOutOfBoundsException e) {
			System.out.println("command 라인에 값을 입력하세요");
		}
		System.out.println("프로그램 종료");
	}
}

9장 예외처리.pdf
0.44MB

728x90
반응형