package com.webex.async;
import java.io.IOException;
import java.sql.SQLException;
public class Test {
/*java.lang.RuntimeException: info three
at com.webex.async.Test.f2(Test.java:24)
at com.webex.async.Test.f1(Test.java:14)
at com.webex.async.Test.main(Test.java:9)
Caused by: java.io.IOException: info two
at com.webex.async.Test.f3(Test.java:33)
at com.webex.async.Test.f2(Test.java:22)
... 2 more
Caused by: java.sql.SQLException: info one
at com.webex.async.Test.f3(Test.java:31)
... 3 more
异常转译,有N个异常,根本原因在最后一个异常,,而对于每个具体异常(或没有转译的单个异常),根本原因在第一个代码;
*/
/*public static void main(String[] args) {
new Test().f1();
}
private void f1() {
try {
f2();
} catch (Exception e) {
e.printStackTrace();
}
}
private void f2() {
try {
f3();
} catch (Exception e) {
throw new RuntimeException("info three", e);
}
}
private void f3() throws IOException {
try {
System.out.println("popup");
throw new SQLException("info one");
} catch (Exception e) {
throw new IOException("info two", e);
}
}*/
/*java.lang.RuntimeException: java.io.IOException: java.sql.SQLException: info one
at com.webex.async.Test.f2(Test.java:67)
at com.webex.async.Test.f1(Test.java:57)
at com.webex.async.Test.main(Test.java:52)
Caused by: java.io.IOException: java.sql.SQLException: info one
at com.webex.async.Test.f3(Test.java:76)
at com.webex.async.Test.f2(Test.java:65)
... 2 more
Caused by: java.sql.SQLException: info one
at com.webex.async.Test.f3(Test.java:74)
... 3 more
异常转译如果不写message,则打印的是层次关系。*/
public static void main(String[] args) {
new Test().f1();
}
private void f1() {
try {
f2();
} catch (Exception e) {
e.printStackTrace();
}
}
private void f2() {
try {
f3();
} catch (Exception e) {
throw new RuntimeException( e);
}
}
private void f3() throws IOException {
try {
System.out.println("popup");
throw new SQLException("info one");
} catch (Exception e) {
throw new IOException(e);
}
}
}
分享到:
2011-09-09 09:57
浏览 747
评论