File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions query

 
Ajay Kumar Rana
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is NumberFormatException subclass of FileNotFoundException ? where can i get the information that one exception class is subclass of another or not.
 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By observing the class hierarchy in API, you can get the information that class is of what type !!!

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NumberFormatException.html


However NumberFormatException in not subclass of FileNotFoundException !!!

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
java.lang.IllegalArgumentException
java.lang.NumberFormatException
[ March 12, 2008: Message edited by: Huzefa Zohaib ]
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would NumberFormatException be a subclass of FileNotFoundException in the first place?

I mean, 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic