• 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

Exception handling question K&B

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Friends I dont have any doubt understanding that answers A, D, E and F are correct as the problem deals with correct usage of over-riding a method.

However, kidly take a look at answer E.
It throws NumberFormatException.
While over-riding a method a narrower exception can be thrown by the overriding method.
This means that NumberFormatException class should be a sub-class of FileNotFoundException ?
Here lies my whole problem. How will we come to know that which class is sub-class of which class. There may be innumerable exception classes. Remembering their hiearchy is very tedious for the exam?
Any clues ?
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NumberFormatException is a Runtime Exception
Try out the foll. code

So, no question of hierarchy arises
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a programmatic exception.
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we can throw the narrow exception or same exception in the overiding method and the RunTimeException
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to me the answers should be A and D.
An Overridden method cannot throw new or broder exceptions. Since NumberFormatException is a new exception, E and F are wrong.
Why would NumberFormatException be a subclass of FileNotFoundException in the first place?
NumberFormatException if not a subclass of FileNotFoundException.
NumberFormatException indicates that a string cannot be formatted into a number. FileNotFoundException indicates a file cannot be found. How are these two events related? They aren't!

On the other hand, FileNotFoundException is a subclass of IOException because it is an exception caused by some form of disk I/O. Similarly, NumberFormatException is a subclass IllegalArgumentException because the string that is formatted is illegal for the formatting methods
[ August 30, 2008: Message edited by: Sirishaaaaa Ghatty ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Sirishaaaaa Ghatty", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,
I am sorry but this is the first time I see a warning about my Display name. I changed it but not sure if that is what is expected. Please let me know if I need to further change it to comply with the rules.
Sorry once again.
Thank you
Sirisha Ghatty
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An overriding method can change these things in the throws clause of the method it overrides...

* It can throw more Un-Checked exceptions,
* It can reduce or remove the Checked exceptions thrown by the overriden method
* It can throw sub-types of checked exceptions thrown by the super-class method...
 
reply
    Bookmark Topic Watch Topic
  • New Topic