我有一个带有父类的已检查异常的方法,它可以抛出父类和子类的异常
public void method() throws ParentException {
if( false ) throw new ParentException();
else if( true ) throw new ChildException(); // this one is thrown
}
Run Code Online (Sandbox Code Playgroud)
我有一个级联catch块,它首先有子例外
try {
method();
} catch (ChildException e) {
// I get here?
} catch (ParentException e) {
// or here?
}
Run Code Online (Sandbox Code Playgroud)
哪个块会捕获抛出的异常?由于该方法仅显式声明了ParentException,因此ChildException是否会显示为ParentException的实例?