关于java自定义异常问题,请高手看看哪里不对了
importjava.io.*;publicclassTestMyException_04{publicstaticvoidmain(Stringargs[]){inta...
import java.io.*;
public class TestMyException_04{
public static void main(String args[]){
int arr[]={1,2,3,4,5};
try{
priarry(arr);
}catch(MyException e){
System.out.print(e);
}
System.out.println("继续!");
}
public static void priarry(int arr[])throws MyException{
for(int i=0;i<=arr.length;i++)
System.out.print(arr[i]+" ");
throw new MyException();
}
}
class MyException extends Exception{
public String toString(){
return("\n数据越界异常!");
}
} 展开
public class TestMyException_04{
public static void main(String args[]){
int arr[]={1,2,3,4,5};
try{
priarry(arr);
}catch(MyException e){
System.out.print(e);
}
System.out.println("继续!");
}
public static void priarry(int arr[])throws MyException{
for(int i=0;i<=arr.length;i++)
System.out.print(arr[i]+" ");
throw new MyException();
}
}
class MyException extends Exception{
public String toString(){
return("\n数据越界异常!");
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询