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.
About Question enthuware.ocpjp.v8.2.1381 :
Moderator: admin
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1381 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sun Jul 31, 2016 12:21 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1381 :
Hi, I have a doubt:
if the try block does not throw any exception, why doesn't catch block is unreachable code?
if the try block does not throw any exception, why doesn't catch block is unreachable code?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1381 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Wed Nov 28, 2018 4:09 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1381 :
Same doubt here.... I chose "will not compile" because I think the catch block is unreachable block. Can anybody please help me on this?sharpmario wrote: ↑Tue Dec 27, 2016 2:05 pmHi, I have a doubt:
if the try block does not throw any exception, why doesn't catch block is unreachable code?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1381 :
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.
Who is online
Users browsing this forum: No registered users and 49 guests