我不断地收到错误:TestException.java:8:error:unreported exception Throwable;必须捕获或声明抛出Java中自定义异常的问题
throw new ParentException().initCause(new ChildException().initCause(new SQLException()));
任何想法,我知道有些小事是缺少这我没有得到容易在我看来,谢谢,不要拿来源为面值,我试图以增加我的理解。
import java.sql.SQLException;
public class TestException{
public static void main(String[] args) {
try{
throw new ParentException().initCause(new ChildException().initCause(new SQLException()));
}
catch(ParentException | ChildException | SQLException e){
e.printStackTrace();
try{
Thread.sleep(10*1000);
}
catch(Exception et){
;
}
}
}
}
class ParentException extends Exception{
public ParentException(){
super("Parent Exception is called");
}
}
class ChildException extends Exception{
public ChildException(){
super("Child Exception is called");
}
}
请缩进代码以便我们更有帮助 –