1. public class A {
2. private void method1() throws Exception {
3. throw new RuntimeException();
4. }
6. public void method2() {
7. try {
8. method1();
9. } catch(RuntimeException e) {
10. System.out.println("Caught Runtime Exception");
11. } catch(Exception e) {
12. System.out.println("Caught Exception");
13. }
14. }
15. public static void main(
String args[]) {
16. A a = new A();
17. a.method2();
18. }
19. }//print "Caught Runtime Exception"
-------------------COMPARE------------------------
public class B {
private void method1() throws Exception {
//throw new RuntimeException();
}
public void method2() {
try {
method1();
} catch(RuntimeException e) {
System.out.println("Caught Runtime Exception");
} catch(Exception e) {
System.out.println("Caught Exception");
}
}
public static void main(String args[]) {
B a = new B();
a.method2();
}
}//compiled,no output?