Page 1 of 1

About Question enthuware.ocpjp.v8.2.1350 :

Posted: Fri Oct 16, 2015 6:36 am
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 :)

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

Posted: Fri Oct 16, 2015 9:48 am
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.

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

Posted: Mon Jun 06, 2016 5:15 pm
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?

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

Posted: Mon Jun 06, 2016 9:42 pm
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.