java异常问题,求解决?
import java.util.Scanner;
class Excep extends Exception{
public void Mess(){
System.out.println("你输入的数据有误!");
}
}
public class test2{
public static void main(String args[]){
int a[] = new int[3];
int k,i=0;
Scanner sc = new Scanner(System.in);
try{
do{
System.out.println("是否输入数据(1、输入 0、退出)");
k = sc.nextInt();
if(k==1){
System.out.println("请输入数组的第"+(i+1)+"个数据:");
a[i] = sc.nextInt();
if(a[i]<0 && a[i]>100){
Excep e = new Excep();
throw e;
}
i++;
}
for(int j=0; j<i; j++)
System.out.println("数组的第"+(j+1)+"个数据:"+a[j]);
}while(k==1);
}catch(Excep e){
e.Mess();
}
}
}
当a不在范围内时为什么接收不了异常?