Order of catching exception in java

Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

A. Yes, it does. The FileNotFoundException is inherited from the IOException. 
Exception's subclasses have to be caught first.

Exception
^
|
IOException
^
|
FileNotFoundException 
So while catching exceptions, we must catch the low level exception first - here : FileNotFoundException .


#The hierarchy in Java Exception framework :





No comments :

Post a Comment

Your Comment and Question will help to make this blog better...