Page 1 of 1

About Question enthuware.ocpjp.v8.2.1381 :

Posted: Wed Aug 31, 2016 3:34 pm
by RoyEL1
In the answers, for bullet 3
"A exception thrown by a failed assertion cannot be caught using a try/catch block."

But in the explanation, you correctly state "A failed assertion throws java.lang.AssertionError, which can be caught by a catch block."
Would it be a better reading of bullet 3 to be
"A exception thrown by a failed assertion cannot be caught using this try/catch block."

You are still drawing out the idea that it is AssertionError that is not derived from Exception, but retains the idea that you can (not recommended) catch them.

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

Posted: Wed Aug 31, 2016 9:37 pm
by admin
Option 3 says, "An exception thrown by a failed assertion cannot be caught using a try/catch block.". It is marked as incorrect and the reason is explained in the explanation.
2.1381.png
2.1381.png (23.55 KiB) Viewed 3975 times

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

Posted: Tue Dec 27, 2016 2:05 pm
by sharpmario
Hi, I have a doubt:

if the try block does not throw any exception, why doesn't catch block is unreachable code?

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

Posted: Wed Dec 28, 2016 7:57 am
by admin
Remember that RuntimeException, which is an unchecked exception, is a subclass of Exception and any RTE can be caught by a catch(Exception e) clause. Therefore, the compiler cannot make a definitive inference that the catch block will not throw any unchecked exception and that is why it has no option but to accept catch(Exception e).

HTH,
Paul.

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

Posted: Wed Nov 28, 2018 4:15 am
by Juno0c
sharpmario wrote:
Tue Dec 27, 2016 2:05 pm
Hi, I have a doubt:

if the try block does not throw any exception, why doesn't catch block is unreachable code?
Same doubt here.... I chose "will not compile" because I think the catch block is unreachable block. Can anybody please help me on this?

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

Posted: Wed Nov 28, 2018 8:53 am
by admin
Please go through the response given above. It answers the question that you are asking. Let me know if you still have a doubt.