문제 2 문제 1에서 작성한 MyCheckedException을 이용하세요. 예제에서 작성한 ExceptionExam을 실행시키면 exam.get50thItem(array);에서 컴파일 오류가 발생합니다. 컴파일 오류가 생기지 않게 적절하게 처리해주세요. (다음 코드로 파일을 두 개 만들어 실습합니다.)
package javaStudy;
public class ExceptionExam{
public static void main(String[] args) {
ExceptionExam exam = new ExceptionExam();
int[] array = new int[10];
________________________
exam.get50thItem(array);
________________________
________________________
}
public int get50thItem(int []array) throws MyCheckedException{
if(array.length < 50) {
throw new MyCheckedException();
}
return array[49];
}
}
실행결과
javaStudy.MyCheckedException: 나의 예외 발생 성공