About Question enthuware.ocpjp.v8.2.1350 :

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
mjerre
Posts: 1
Joined: Fri Oct 16, 2015 6:24 am
Contact:

About Question enthuware.ocpjp.v8.2.1350 :

Post by mjerre »

Apparantly the answer is supposed to be "It will throw an exception at runtime", which I can agree with given that the code would compile. However, the first statement "Connection c = ...." is outside the try-with-resources statement and will result in a compiler error unless the statement is moved inside the try-with-resources parantheses thingy, or if the surrounding method throws SQLException, which is not specified in the text.

It would be nice if you could correct this :)

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

Re: About Question enthuware.ocpjp.v8.2.1350 :

Post by admin »

The code will not compile even if you move it inside the try block because it is not complete code. There is no encompassing method or class for it to compile and run.

In such cases, where you see partial code listing, you need to assume that the given code is present in appropriate context of a method/class. In this case, the encompassing method can be assumed to have appropriate throws clause.

HTH,
Paul.

RAZER-KIEV
Posts: 17
Joined: Thu Oct 01, 2015 4:06 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1350 :

Post by RAZER-KIEV »

The method rsmd.getColumnName(0) will throw SQLException, witch must be cached by the catch block. So it will handle it, print stackTrace but and application will not throw any exception and will finish correctly, isn't?

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

Re: About Question enthuware.ocpjp.v8.2.1350 :

Post by admin »

You are right. It should say print an exception stack trace instead of throw an exception. Fixed.
thank you for your feedback!
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests