Given:
3. public class Main { 4. public static void main(String[] args) { 5. // insert code here 6. 7. } 8. void go() { 9. go(); 10. } 11. }
And given the following three code fragments:
I. new Main().go(); II. try { new Main().go(); } catch (Error e) { System.out.println("ouch"); } III. try { new Main().go(); } catch (Exception e) { System.out.println("ouch"); }
When fragments I-III are added, independently, at line 5, which are true?
Choose all that apply.
B and E are correct.
go()
is a recursive method which is guaranteed to cause a StackOverflowError.
Since Exception is not a superclass of Error, catching an Exception will not help handle an Error, so fragment III will not complete normally.
Only fragment II will catch the Error.