我在调用getCause
.Throwable
package com.salman.demo;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
NormalClass.testIt();
} catch (Throwable th) {
System.out.println(th.getCause());
}
}
}
package com.salman.demo;
import com.salman.exceptions.ValidationException;
public class NormalClass {
public static void testIt() throws ValidationException {
System.out.println("Inside testIt funtion.");
throw new ValidationException("Validation Exception..");
}
}
在运行MyClass
时,它会打印以下输出
Inside testIt funtion.
null
但是在调试时,我可以看到原因私有变量的值设置ValidationException
为预期的值,但是在调用该私有字段的 getter 时返回 null。