【发布时间】:2015-07-10 17:31:37
【问题描述】:
我不断收到错误:TestException.java:8: error: unreported exception Throwable;必须被抓住或宣布被扔掉
抛出新的 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");
}
}
【问题讨论】:
-
请更好地缩进您的代码,以便我们提供更多帮助