//自定义异常要继承一个异常接口
class MyException extends Exception {
public MyException() {}
public MyException(String msg) {
super(msg);
}
}
public class ExceptionDemo3 {
public static void main(String[] args) throws MyException {
try {
int i = 10/0;
System.out.println("有没有执行 i="+i);
} catch (ArithmeticException e) {
System.out.println("Catch My Exception");
throw new MyException("我自己定义的错误");
}
}
}
java自定义异常练习
最新推荐文章于 2021-07-26 15:50:29 发布