Page 1 of 1

About Question enthuware.ocpjp.v7.2.1205 :

Posted: Sat Jan 26, 2013 8:51 pm
by ETS User
I don't understand why the answer says that it does not compile ? The code snippet compiles fine when I copied it into eclipse.
FileNotFoundException is a subclass of IOException and in a multi-catch block we cannot have both subclass and parent class. But FileNotFoundException by itself in the multi-catch block seems to work fine.
Can anyone given an explanation for this answer.

Re: About Question enthuware.ocpjp.v7.2.1205 :

Posted: Sat Jan 26, 2013 9:08 pm
by admin
Are you sure you tried the exact same code as given in the question? Because I just tried it and it gives an error while compilation:
error: unreported exception IOException; must be caught or declared to be thrown
The reason is exactly as given in the explanation. The code in the try block throws IOException and a catch block that catches FileNotFoundException is too narrow to catch IOException.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1205 :

Posted: Sat Jan 26, 2013 9:11 pm
by ETS User
OK sorry I was referring to a different code snippet which had the throws clause in the main. I was a bit hasty, my question is wrong :(

Re: About Question enthuware.ocpjp.v7.2.1205 :

Posted: Mon Nov 11, 2013 3:15 pm
by jeremy_dd
I wouldlike to report an error that is very misleading :

public static void copy(String records1, String records2) throws IOException {         try (               



Because of this parenthesis , instead of a brace, i answered option 1)

Jeremy

Re: About Question enthuware.ocpjp.v7.2.1205 :

Posted: Mon Nov 11, 2013 8:30 pm
by admin
This has now been fixed.
thank you for your feedback!
Paul.