Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Mala Gupta's Mock exam question #12

 
Winston Liek
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question says:

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
checked exceptions.
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?
 
Rico Felix
Ranch Hand
Posts: 407
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roel De Nijs
Sheriff
Posts: 10230
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic