JAVA小练习78——抛出处理(throw,throws)

    xiaoxiao2023-10-29  152

    class Demo78 { public static void main(String[] args) { try{ div(4,0,null); }catch(Exception e){ e.printStackTrace(); System.out.println("哎呀,出错了..."); } } public static void div(int a , int b,int[] arr) throws Exception,NullPointerException { if(b==0){ throw new ArithmeticException();//抛出一个异常对象。 }else if(arr==null){ throw new NullPointerException(); } int c = a/b; System.out.println("结果:"+ c); } }
    最新回复(0)