java 基础 异常

1.关键字

2.用法

 

1.关键字

throw

try

catch

finally

Objects

Throwable

2.用法

 

 

 

package com.jack.test2;


import java.util.Objects;

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

        test1(null);
    }

    public static void test1(int[] arr) {
        if (arr == null) {
            try {
                throw new Exception("参数为空1");
            } catch (Throwable e) {
                System.out.println(e.getMessage());
                System.out.println(e.toString());
                e.printStackTrace();
            }
//            catch (Exception e) {
//                System.out.println(e.getMessage());
//                System.out.println(e.toString());
//                e.printStackTrace();
//            }
        }
        //Objects.requireNonNull(arr, "参数为空");
        System.out.println(1111);
    }

}

  

package com.jack.test2;
//
//public class testException extends Exception {
//    public testException(String message) {
//        super("自定义类"+message);
//    }
//
//    public testException() {
//        super();
//    }
//}


public class testException extends RuntimeException {
    public testException(String message) {
        super("自定义类"+message);
    }

    public testException() {
        super();
    }
}

 




 

 

posted on 2020-03-28 10:49  biind  阅读(128)  评论(0编辑  收藏  举报