Java 异常抛出

来源:互联网 发布:switch用法c语言 编辑:程序博客网 时间:2024/06/05 10:09
class Demo{public void method(int []arr,int index){System.out.println(arr[index]);//(虚拟机 先new 再 throw给主函数) throw new ArrayIndexOutOfBoundsException(idnex)  }}class ExceptionDemo2{public static void main(String[] args) { int arr[]=new int [100];Demo d=new Demo();d.method(arr,100);//throw new ArrayIndexOutOfBoundsException(idnex)  //主函数再抛给虚拟机 虚拟机将其打印在控制台}}

原创粉丝点击