About Question enthuware.ocajp.i.v8.2-.-1496 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
swarna pakeer
Posts: 16
Joined: Thu Mar 19, 2020 2:27 pm
Contact:

About Question enthuware.ocajp.i.v8.2-.-1496 :

Post by swarna pakeer »

option B says "RuntimeException and its subclasses are used for recoverable situation" and explanation in option C says "It is true that neither Errors nor RuntimeExceptions should be used for recoverable". could you please clarify which is correct.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

Option B is mistakenly set as the right option. Option C is the right option.
All the explanations are correct. i.e.
RuntimeExceptions such as NullPointerException, IndexOutOfBoundsException indicate that there is a coding error in the program. Ideally, a program should never encounter such exceptions. Therefore, if a program encounters a RuntimeException, it should be left unhandled. Instead of catching the exception, the code should be fixed and this exception should be eliminated.

Fixed.

thank you for your feedback.
If you like our products and services, please help us by posting your review here.

swarna pakeer
Posts: 16
Joined: Thu Mar 19, 2020 2:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by swarna pakeer »

okay but i still see that B is marked as correct option.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

It will be reflected in the updated question bank file.
If you like our products and services, please help us by posting your review here.

swarna pakeer
Posts: 16
Joined: Thu Mar 19, 2020 2:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by swarna pakeer »

ok. and i see that Oracle documentation says "Exception is the superclass of all the exceptions from which ordinary programs may wish to recover.Error is the superclass of all the exceptions from which ordinary programs are not ordinarily expected to recover." did they mention anywhere saying Runtiime exceptions are not recoverable ? because as per above Runtime Exceptions may be recoverable.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

From https://docs.oracle.com/javase/tutorial ... ntime.html
Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.
If you like our products and services, please help us by posting your review here.

swarna pakeer
Posts: 16
Joined: Thu Mar 19, 2020 2:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by swarna pakeer »

from the book "Hanuman Deshmukh" , it said " It is possible to recover from runtime exceptions but ideally, since they indicate bugs in the code, you should not attempt to catch them and recover from them. A well written program should not cause the JVM to throw runtime exceptions".

So above statement says Runtime Exceptions are recoverable right? Am really not able to decide if there is a situation where i need to choose one option among these two .A) Runtime Exceptions are not recoverable B) Errors are not recoverable.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

The book is also correct. It is saying the same thing from another perspective. You can put use a try-catch to catch any RuntimeException or even an Error (obviously, because catch clauses takes a Throwable). So, it is technically valid. But should u do that? That is the issue.

Bottom line is this - runtime exceptions and errors are considered unrecoverable from a logical perspective. From the coding perspective, it is possible to recover from them by catching them but you should not do so.

If you catch, for example, ArrayIndexOutOfBoundsException, in your code, what are you going to do? You can't change the array at runtime. Ideally, the code should not have tried to access the array beyond the last element. So, it is really a coding issue. In that sense, an ArrayIndexOutOfBoundsException is not considered recoverable. But a novice programmer may add logic to their code in the catch(ArrayIndexOutOfBoundsException ae) block. It would be technically legal but is not the right thing to do.
If you like our products and services, please help us by posting your review here.

aevora
Posts: 5
Joined: Wed May 06, 2020 2:02 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by aevora »

I think the answer is misleading.
Neither Errors nor RuntimeExceptions are used for recoverable situations. Both should be identified during testing and eliminated by fixing the code.
I agree with the first part but the second part made me choose a wrong answer because it seems to imply that all RuntimeExceptions and Errors are avoidable by fixing the code, and usually that is not the case. For example: An application is trying to call a Web Service or access a shared resource but the network is down.

I would suggest to modify the second part with something like:
Both should be identified during testing and eliminated, as much as possible, by fixing the code.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

No, it is correct. In your example, if an application is trying to call a Web Service or access a shared resource but the network is down, then it should expect (and handle) a checked exception, not unchecked (i.e. Error/RuntimeException) exceptions.
If you like our products and services, please help us by posting your review here.

aevora
Posts: 5
Joined: Wed May 06, 2020 2:02 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by aevora »

Then think about an OutOfMemoryError because there are too many users using the application and the JVM has not enough memory available. My point is that Errors and RuntimeException are not always avoidable by fixing the code as the answer suggest.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

Errors are not fixable by code. They should not be caught because they indicate an issue with the environment.
RuntimeExceptions are fixable and therefore, should not be caught. Code should be fixed instead.

So, basically, the bottom line is that unchecked exceptions are not meant to be caught.

You can argue all you want about it but this is the official theoretical position. This is how you need to answer the question in the exam.
If you like our products and services, please help us by posting your review here.

aevora
Posts: 5
Joined: Wed May 06, 2020 2:02 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by aevora »

Errors are not fixable by code.
That's exactly what I am saying.

So, below, the word Both should be removed.
Neither Errors nor RuntimeExceptions are used for recoverable situations. Both should be identified during testing and eliminated by fixing the code.

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

Re: About Question enthuware.ocajp.i.v8.2.1496 :

Post by admin »

OK, got you! Sorry, I don't know what I was thinking.
-Paul.
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 5 guests