【发布时间】:2011-04-14 18:32:12
【问题描述】:
我只是想更好地理解这一点。
我知道有很多不同的exception types,根据我所做的一些阅读,所有异常类型都被异常捕获。首先,我能确定这是真的吗?
try{
...
}
catch(Exception x){
//No matter what fails in the try block, x
//will always have a value since all exception
//types are caught under Exception? I guess
//What I really want to know, is will this ever
//Fail?
}
catch(SystemException x){
//This code will never execute since all
//exceptions are caught in the first catch?
}
接下来,这个捕捉层次结构是如何工作的?如果 Exception 位于顶部,那么其他所有异常类型是否都在 Exception 下一级,或者是否存在多个类型层,例如 Exception 是否是 ExceptionSomething 的父级,它是 ExceptionSomethingElse 的父级?
附录:
或者如果我们有这样的代码:
try{
...
}
catch(SystemException x){
//If there is an exception that is not a SystemException
//code in this block will not run, right (since this is
//looking specifically for SystemExceptions)?
}
【问题讨论】: