java异常结构

    xiaoxiao2021-08-16  138

    结构如下:       

                   Throwable

    Error                           Exception

                    RuntimeException          非RuntimeException(编译时检查)

    几个关键字:try catch finally throws throw

    异常的继承:

    public class MyException extends Exception { private int id; //每个异常有一个id号 public MyException(String message, int id){ super(message); this.id = id; } public int getId() { return id; } public void setId(int id) { this.id = id; } } public class City { public static void main(String[] args) { int i = 0; if(i==0){ try { throw new MyException("haha", 0); } catch (MyException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } test4.MyException: haha at test4.City.main(City.java:11)

    转载请注明原文地址: https://ju.6miu.com/read-676441.html

    最新回复(0)