About Question enthuware.ocpjp.v8.2.1381 :

Moderator: admin

Post Reply
RoyEL1
Posts: 10
Joined: Tue Aug 09, 2011 3:23 pm

About Question enthuware.ocpjp.v8.2.1381 :

Post by RoyEL1 » Wed Aug 31, 2016 3:34 pm

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.

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

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

Post by admin » Wed Aug 31, 2016 9:37 pm

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 2564 times
If you like our products and services, please help us by posting your review here.

sharpmario
Posts: 4
Joined: Sun Jul 31, 2016 12:21 pm
Contact:

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

Post by sharpmario » 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?

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

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

Post by admin » Wed Dec 28, 2016 7:57 am

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.
If you like our products and services, please help us by posting your review here.

Juno0c
Posts: 1
Joined: Wed Nov 28, 2018 4:09 am
Contact:

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

Post by Juno0c » Wed Nov 28, 2018 4:15 am

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?

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

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

Post by admin » Wed Nov 28, 2018 8:53 am

Please go through the response given above. It answers the question that you are asking. Let me know if you still have a doubt.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest