结构如下:
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)