Page 1 of 1
About Question enthuware.ocpjp.v8.2.1273 :
Posted: Mon May 09, 2016 10:20 am
by beaucarnes
What am I missing in the code for this question? The answer says that it throws a java.lang.Exception but as far as I can tell the code never gets to that point because while opening the resource it throws IOException. So why isn't the answer IOException?
Re: About Question enthuware.ocpjp.v8.2.1273 :
Posted: Mon May 09, 2016 9:38 pm
by admin
There is no call to open. You should try running the code.
HTH,
Paul.
Re: About Question enthuware.ocpjp.v8.2.1273 :
Posted: Tue Aug 06, 2019 5:26 pm
by dongyingname
My question is not really related to the topic here:
I knew a try-block must be followed by a catch or a finally or both. But why the single try-block in the main method is successfully compiled?
Re: About Question enthuware.ocpjp.v8.2.1273 :
Posted: Tue Aug 06, 2019 10:31 pm
by admin
dongyingname wrote: ↑Tue Aug 06, 2019 5:26 pm
I knew a try-block must be followed by a catch or a finally or both. But why the single try-block in the main method is successfully compiled?
Because it is not a try block. It is a
try-with-resources block.