JAVA异常的定位问题方法

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);
}
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值