java exception e抛异常_抛出的异常在上层catch到,但是e.getMessage()为NULL,为什么会这样?...
1.在一個代碼里catch到Exception,throw new Exception(e.getMessage());
在上級代碼里catch到拋出的Exception,想得到錯誤的信息,結(jié)果發(fā)現(xiàn)e.getMessage()卻為null
debug的時候發(fā)現(xiàn)拋出的e里面有個undeclaredThrowable,這個才是拋出的異常。不懂這到底是什么原理。
2.代碼如下
server層代碼:
public A methodA(){
try{
int a = 10/0;//這里會拋出ArithmeticException
} catch(Exception e){
throw new Exception(e.getMessage());
}
return null;
}
control層代碼:
public methodB(){
try{
A a = sercer.methodA();
} catch(Exception e){
System.out.println(e.getMessage());//這里為NULL
}
}
這個是debug看到的信息,不是Exception,也不是ArithmeticException,而是UndeclaredThrowableException。在undeclaredThrowable里面有著底層拋出的信息。
3.這是什么原因造成。不是特別能理解
總結(jié)
以上是生活随笔為你收集整理的java exception e抛异常_抛出的异常在上层catch到,但是e.getMessage()为NULL,为什么会这样?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 匿名函数 构造_Java匿名内
- 下一篇: java char 初始化为空格_jav