Estou com dúvida na seguinte pergunta do teskiller.
Segue.
Click the Exhibit button.
public class A {
public void method1() {
try {
B b=new B();
b.method2();
// more code here
} catch (TestException te) {
throw new RuntimeException(te);
}
}
}
public class B {
public void method2() throws TestException {
// more code here
}
}
public class TestException extends Exception {
}
Given
public void method() {
A a=new A();
a.method1();
}
Which is true if a TestException is thrown on line 14 (class B)?
A. Line 3 (public void method) must be called within a try block.
B. The exception thrown by method1 in class A is not required to be
caught.
C. The method declared on line 1(public void method) must be declared to throw a
RuntimeException.
D. On line 5 of class A, the call to method2 of class B does not need to
be placed in a try/catch block.
Resposta Certa: B
Pensei que a correta fosse a letra A, pois se chamarmos a linha 3 dentro do try/catch, não seria lançado exceção.
Pois se rodar desse jeito dá exceção.