Given the invocation "java Main" and:
2. public class Main { 3. public static void main(String[] args) throws Exception { 4. try { /*from ww w . ja v a2s . c o m*/ 5. assert false; 6. System.out.print("t "); 7. } 8. catch (Error e) { 9. System.out.print("c "); 10. throw new Exception(); 11. } 12. finally { System.out.print("f "); } 13. } }
What is the result?
C is correct.
It's legal (although not recommended) to catch an Error.
It's also legal for main()
to throw an exception.
The trick to this question is that assertions were not enabled, so line 5 is skipped, and no Error is thrown.
If the invocation had been "java -ea Main", then answer E would have been correct.