Click the Exhibit button.
1. public class A {
2. public void method1() {
3. try {
4. Bb=newB();
5. b.method2();
6. // more code here
7. } catch (TestException te) {
8. throw new RuntimeException(te);
9. }
6. }
7. }
1. public class B {
2. public void method2() throws TestException {
3. // more code here
4. }
5. }
1. public class TestException extends Exception {
2. }
Given:
31. public void method() {
32. Aa=newA();
33. a.method1(); 34. }
Which is true if a TestException is thrown on line 3 of class B?
A. Line 33 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 31 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.
Answer: B问题一:B 选项中:class A 中的method1()所抛出的exception为什么是is not required to be
caught.??谢谢
1. public class A {
2. public void method1() {
3. try {
4. Bb=newB();
5. b.method2();
6. // more code here
7. } catch (TestException te) {
8. throw new RuntimeException(te);
9. }
6. }
7. }
1. public class B {
2. public void method2() throws TestException {
3. // more code here
4. }
5. }
1. public class TestException extends Exception {
2. }
Given:
31. public void method() {
32. Aa=newA();
33. a.method1(); 34. }
Which is true if a TestException is thrown on line 3 of class B?
A. Line 33 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 31 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.
Answer: B问题一:B 选项中:class A 中的method1()所抛出的exception为什么是is not required to be
caught.??谢谢
因为class B的抛出的异常是 TestException ,而class A 的method1方法中catch (TestException te)捕获了这个异常,
所以其他地方再调用a.method1()的时候不需要捕获这个异常。