public class First {
protected void method1() throws CustomException {
int number=10/0;
System.out.println("method 1" + number);
throw new CustomException("Divided by zero");
}
public class Second extends First {
protected void method2() {
method1();
}
public class Third extends Second {
protected void method3(){
try {
method2();
}
catch (CustomException ex)
{
System.out.println("Caught the exception");
System.out.println(ex.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,首先抛出一个异常,我想从第三个捕获它(第二个不会处理错误)。但是第二个方法调用不会让我通过。我怎样才能解决这个问题?