自己写的exception
package test;
public class MyException extends RuntimeException{
public MyException(String message){
super(message);
}
}
package test;
public class a {
static void x() throws MyException{
throw new MyException("hree exception");
}
public static void main(String[] args){
try{
x();
}catch(MyException e){
System.out.println(e.getMessage());
}
}
}
java exception 分
1.检查异常,这类异常必须处理,如远程地址等
2.运行异常,这类异常必须处理,如数组越界等
3.错误,如内存溢出等
异常一般是谁调用,谁处理,将异常向上抛给调用的方法