Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eeceptions

 
amrit singh
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all !!!
when catching multiple exception the class hierarchy of exception is imortant i mean more specific must come b4
is this also true when we declare in throws statement
 
steve richardson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, when a method is declared to throw a number of Exceptions, there is no requirement to list these in any particular order of precedence. Generally though, you should try and throw as specifically as you can to help the client programmer and make the code cleaner and easier to read. On the other hand, though, if you have a method that throws five different exceptions that are all, say, sub-classes of IOException, it is better to simply say throws IOException, and then to catch the specific sub-classes in the calling code. Hope this is of some use.
Regards,
Steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic