class FuShuIndexExecption extends Exception
{
FuShuIndexException(){}
FuShuIndexException(String s)
{
super(s);
}
}
class Person
{
public int show(int[] arr,int index)
{
if(arr==null)
throw new NullPointerException("数组角标不能为空");
if(index>=arr.length)
{
throw new ArrayIndexOutOfBoundsException("数组角标越界啦");
}
if(index<0)
{
throw new FuShuIndexException();
}
return(arr[index]);
}
}
class ExceptionDemo5
{
public static void main(String[] args)
{
int[] arr = new int[3];
Person p = new Person();
//arr =null;
p.show(arr,-3);
//ExceptionDemo5.method(arr,3);
}
/*
public static void method(int[] arr,int index)
{
System.out.println(arr[index]);
}
*/
} |
|