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.   

    答:因为 RuntimeException是一个unchecked exception.
      

  2.   


    因为class B的抛出的异常是 TestException ,而class A 的method1方法中catch (TestException te)捕获了这个异常,
    所以其他地方再调用a.method1()的时候不需要捕获这个异常。
      

  3.   

     throw new RuntimeException(te); 这儿有误,因为运行时的异常是我们事先很难觉察发现的,比如说除数为0,我们在做一个运算,很多步骤,根本不知哪里会出现除数为0,为了减小程序员的工作量,Java虚拟机帮我们把这事情做了,无需我们担心了。运行时异常还包括数组越界,等等。