newExc
newExc是什么意思?从哪里来的?好像没有定义过啊!!
newExc是什么意思?从哪里来的?好像没有定义过啊!!
2016-07-23
public class test_1 {
public static void main(String[] args) {
test_1 result = new test_1();
result.deal2();
}
public class DIYException1 extends Exception {
public DIYException1() {
}
}
public class DIYException2 extends Exception {
public DIYException2() {
}
}
//自定义两种异常
public void test() throws DIYException1 {
throw new DIYException1();
}
//通过test(),抛出异常1
public void deal1() throws DIYException2 {
try {
test();
} catch (DIYException1 e) {
System.out.println("error1");
throw new DIYException2();
}
}
//检测到异常1抛出后,抛出异常2,并输出error1
public void deal2() {
try {
deal1();
} catch (DIYException2 e) {
System.out.println("error2");
}
}
//检测到异常2后,输出error2
}
.initCause()是Exception中封装好的一些方法
举报