8.9 例外のキャプチャとファイル

1. 例外キャプチャ

public class TestException {
    public static void main(String[] args)  {

        //1.ArithmeticException
        //2.ArrayIndexOutOfBoundsException
        //3.NullPointerException
        /**
         try {
         int i = 2 / 0;
         System.out.println("111111111");
         }catch(ArithmeticException e){
         System.out.println("除数不能为0 ");
         }finally {
         System.out.println("22222222222");
         }
         **/
        div(1,0);
        //    Class.forName("11111");



    }

    static int div(int a,int b) throws ArithmeticException{
        int c=a/b;
        return c;
    }

    //异常处理方式:   1.jvm 处理   运行java程序的抽象计算机  异常名称  异常信息 异常出现的位置
    //               2.自己处理   (1) try  catch  finally
    //                             (2)  throws

    //所有异常的父类都是Exception

    //异常的类型
    //1.运行时异常  extends RuntimeException
    //2.编译异常   必须自己处理

}

2.ファイル

おすすめ

転載: blog.csdn.net/zlc2351951436/article/details/99290368