I need help with the following code:
1. public class Test242 {
2. public static void main (String [] args) {
3. try {
4. foo();
5. System.out.println("rock ");
6. }
7. catch(Exception e) {
8. System.out.println("paper ");
9. }
10. finally {
11. System.out.println("scissors ");
12. }
13. System.out.println("wins ");
14. }
15. static void foo() { }
16. }
The answer says the output would be: rock scissors wins. However, I though we are never supposed to write a catch block for exceptions that would never be thrown in te try block. This will generate a compiler error. I don't see the try block throwing any exceptions since neither foo() nor the print statement throw any exceptions. Why doesn't the code generate a compile-time error? Can someone explain this to me? Thank you!
[ September 06, 2006: Message edited by: Maggie Ling ]