public class Test{
public static void main(String args[]){
int array[] = new int[2];
try{
a(array, 10);
}catch(RuntimeException e){
System.err.println("mainメソッド内で例外を処理をしました("+e+")");
}
}
public static int a(int array[], int i) throws ArrayIndexOutOfBoundsException{
if( i < 0 || i >= array.length ){
System.out.println("ArrayIndexOutOfBoundsExceptionを投げます");
throw new ArrayIndexOutOfBoundsException();
}
System.out.println("aメソッドは正常に終了します");
return array[i];
}
}
|