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.
About Question enthuware.ocpjp.v7.2.1205 :
Moderators: Site Manager, fjwalraven
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1205 :
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:
HTH,
Paul.
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.error: unreported exception IOException; must be caught or declared to be thrown
HTH,
Paul.
Re: About Question enthuware.ocpjp.v7.2.1205 :
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 

-
- Posts: 9
- Joined: Mon Nov 11, 2013 3:11 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1205 :
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
public static void copy(String records1, String records2) throws IOException { try (
Because of this parenthesis , instead of a brace, i answered option 1)
Jeremy
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1205 :
This has now been fixed.
thank you for your feedback!
Paul.
thank you for your feedback!
Paul.
Who is online
Users browsing this forum: No registered users and 16 guests