1.在一个代码里catch到Exception,throw new Exception(e.getMessage());
在上级代码里catch到抛出的Exception,想得到错误的信息,结果发现e.getMessage()却为null
debug的时候发现抛出的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.这是什么原因造成。不是特别能理解
如果你要输出异常信息:
如果是得到异常信息:
关于异常相关的东西其实也不少,有兴趣可以好好看看API及解读一下源码