java中的自定义异常,帮忙编写一下
发布网友
发布时间:2022-07-13 17:10
我来回答
共1个回答
热心网友
时间:2023-11-07 14:06
异常类:
public class MyException extends Exception{
private static final long serialVersionUID = 1L;
public MyException(){
super("我是自定义异常");
}
}
自定义测试类:
public class MyExceptionClass {
private void throw1() throws MyException{
throw new MyException();
}
private void throw2(){
try {
throw1();
} catch (MyException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new MyExceptionClass().throw2();
}
}