Given:
5. static String s = ""; 6. public static void main(String[] args) { 7. try { m(args); } 8. catch (Error e) { s += "e "; } 9. s += "x "; 10. System.out.println(s); //from w w w . j a va 2s . co m 11. } 12. static void m(String[] args) { 13. if(args.length == 0) 14. throw new IllegalArgumentException(); 15. s += "d "; 16. }
And, if the code compiles, and given a java invocation with no arguments, what is the result? (Choose all that apply.).
G is correct.
It's legal, although uncommon to catch Errors.
It's legal to shadow the variable name "args".
It's legal to throw a runtime exception without handling it or declaring it.
And finally, the catch block doesn't catch the exception because exceptions don't extend from Error.