It is true that it is wrong to number columns from zero. But neither the question nor the explanation says that it is ok to number columns from 0. It just that in this case, the given code does not compile, so the question of throwing exception does not arise.
If you like our products and services, please help us by posting your review here.
It will not compile.
Observe that the declaration of try-with-resources statement is wrong. The type of the resource must be specified in the try itself. i.e. it should be: try(Statement stmt = c.createStatement())
Meaning that the resource used in try with resources in this example "stmt" must be final or effectively final or declare like in the explanation.
Am I correct?
Yes, the try-with-resources resource must either be a variable declaration or an expression denoting a reference to a final or effectively final variable.
Enhanced the explanation to make it clearer.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
The unhandled exception problem that you are getting is because you are assuming that the code fragment is in a method without any throws clause. The note at the bottom is now updated as:
(Assume that the method in which this code appears has appropriate throws clause.)
thank you for your feedback!
If you like our products and services, please help us by posting your review here.