• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Mala Gupta's Mock exam question #12

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic