Wednesday, May 14, 2008

Does the order of catch statements for FileNotFoundException and IOException matter?

Yes. IOException is the super class of FileNotFoundException. So, if you put the catch statement for IOException above that for FileNotFoundException, then the code for second catch will become unreachable and the compiler will throw an error for that. Reason is simple: every object of a sub class can be easily accepted by a super class reference.


No comments: