Which of the following statements are correct? (Select 3 options)
a You may not be able to handle all the checked exceptions in your code.
b If required, you can handle all the runtime exceptions in your code.
c You can handle an exception in your code even if you don’t know its exact name.
d A single exception handler can be used to handle all types of runtime and
e You must handle all errors that can be thrown by your code.
f Runtime exceptions are also known as checked exceptions.
the correct answers are B,C,D
My question is, isn't it A also correct?
Since 'handle' means catching exceptions, if you were not able to handle it, you can 'declare' it, right?
I am thinking to myself it was not included in the correct answers because of the fact that checked exceptions are supposed to be handled in code even if a method declares it, it will still have to be caught along the lines somewhere. That was the main design of the exception handling mechanism so that offending blocks of code can be identified and handled with a logical and systematic approach.
The wording of answer A is a little bit unclear. It's also the only one of the possible answers with a negation in the statement. And it's always harder to assess a negative statement than a positive one.
I guess it should be interpreted as "there are checked exceptions in your code which can not be handled". Of course that statement would be incorrect, because every checked exceptions can be handled by adding a catch block. But maybe answer A should be read as "it's not needed to handle (using the catch block) all the checked exceptions in your code". This interpretation would be true, because I can declare (as in "adding a throws clause to the method) the checked exception to every method in the method call stack (including the main method).
I'll contact the author of the book and ask Mala if she could chime in and share her thoughts.