About Question enthuware.ocpjp.v7.2.1205 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.ocpjp.v7.2.1205 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

ETS User

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

Post 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 :(

jeremy_dd
Posts: 9
Joined: Mon Nov 11, 2013 3:11 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

This has now been fixed.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests