On Jul 3, 11:16 am, Rohit Bansal <[email protected]> wrote: > *Friends, I had a doubt regarding Exception class hierarchy. If anyone > thinks of a solution kindly reply back.* > *We know subclasses always have an extended functionality of superclass- > i.e. all functions of superclass are necessary to be there in subclass too > then the problem is* > > Suppose my code is somewhat like: > > try > { > //code here > > } > > catch( IOException e ) > {} > > This works fine, now we have IOException subclass of superclass > Exceptionthen how come on replacing IOException by Exception also, the > code has no > more problem.I know that Exception is a generalised class but IOException I hope I understand your post correctly. Anyway, replacing catch parameter from IOException to Exception changes the granularity of what the handler would trap. For example: // Traps IOException and it's subclasses. catch(IOException e) // Traps All exceptions, including IOException. catch(Exception e)
Sorry if my post is off topic. > being a subclass must not only have functionality of Exception class but > also added specific functionality. > > -- > Rohit. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
