37

学习内容:

1.使用throws关键字抛出异常

代码示例:

public class Shoot {

static void pop()throws NegativeArraySizeException{//定义方法
int[]arr=new int[-3];//创建数组
}
public static void main(String[] args) {
try {
pop();
}catch(NegativeArraySizeException e){
System.out.println("pop()方法异常");//输出异常信息
}

}

}

运行截图:

posted @ 2020-08-12 21:15  枫叶鎏霜  阅读(91)  评论(0)    收藏  举报