网站开发搜索功能,网站百度快照怎么做,河北邢台穷吗,如何把静态图片做成动态视频一、异常对象的产生原因和处理方式 二、异常的抛出 1 public class Demo01 {2 /*3 * Throwable:Exception、Error4 * Exception-RuntimeException5 * 异常中的关键字#xff1a;throw,在方法内部#xff0c;抛出异常6 * 7 * 方法中声明…一、异常对象的产生原因和处理方式 二、异常的抛出 1 public class Demo01 {2 /*3 * Throwable:Exception、Error4 * Exception-RuntimeException5 * 异常中的关键字throw,在方法内部抛出异常6 * 7 * 方法中声明异常关键字8 * throws用于在方法上的声明上标明此方法可能出现异常9 * 请调用者处理
10 */
11 public static void main(String[] args) throws Exception{
12 int[] arr {};
13 int i getArray(arr);
14 System.out.println(i);
15 }
16 public static int getArray(int[] arr)throws Exception{
17 //方法合法性的判断
18 if(arrnull){
19 //抛出异常的形式告诉调用者
20 //关键字throw
21 throw new Exception(传递的数组不存在);
22 }
23 //对数组进行判断判断数组中是不是有元素
24 if(arr.length0){
25 //抛出异常
26 throw new Exception(数组中没有任何元素);
27 }
28 int i arr[arr.length-1];
29 return i*2;
30 }
31 } 转载于:https://www.cnblogs.com/Nelsoner/p/6701615.html