About Question enthuware.ocajp.i.v8.2-.-1496 :
Moderators: Site Manager, fjwalraven
-
- Posts: 16
- Joined: Thu Mar 19, 2020 2:27 pm
- Contact:
About Question enthuware.ocajp.i.v8.2-.-1496 :
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
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.
-
- Posts: 16
- Joined: Thu Mar 19, 2020 2:27 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
okay but i still see that B is marked as correct option.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
-
- Posts: 16
- Joined: Thu Mar 19, 2020 2:27 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
-
- Posts: 16
- Joined: Thu Mar 19, 2020 2:27 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
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.
-
- Posts: 5
- Joined: Wed May 06, 2020 2:02 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
I think the answer is misleading.
I would suggest to modify the second part with something like:
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.Neither Errors nor RuntimeExceptions are used for recoverable situations. Both should be identified during testing and eliminated by fixing the code.
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
-
- Posts: 5
- Joined: Wed May 06, 2020 2:02 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
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.
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.
-
- Posts: 5
- Joined: Wed May 06, 2020 2:02 am
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
That's exactly what I am saying.Errors are not fixable by code.
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.
-
- Site Admin
- Posts: 10322
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1496 :
OK, got you! Sorry, I don't know what I was thinking.
-Paul.
-Paul.
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 7 guests