我正在阅读来自https://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html的Throwable类,但我无法理解链式异常工具。所以有人可以帮助我。
答案 0 :(得分:2)
正如Oracle doc所说
Chained Exception Facility
Java代码通常会捕获一个异常并抛出另一个异常
这里有TutorialsPoint的例子:
public class Main{
public static void main (String args[])throws Exception {
int n = 20, result = 0;
try {
result = n/0;
System.out.println("The result is"+result);
} catch(ArithmeticException ex) {
System.out.println ("Arithmetic exception occoured: "+ex);
try {
throw new NumberFormatException(ex);
} catch(NumberFormatException ex1) {
System.out.println ("Chained exception thrown manually : "+ex1);
}
}
}
}