• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why do i need to handle IOException even though I have declared BusinessException in throws clause.

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my below code, BusinessException is subclass of Exception.
IOException is subclass of Exception that means IOException is also a subclass of BusinessException then why method saveFileToServer(..) needs to catch IOException even though i have declared throws BusinessException on saveFileToServer(..).



Can anybody clear my doubt ?
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoa! I'm not following your train of though. If A extends B, and C extends B, then A doesn't extend C. Or IOW, if Dog is an Animal, and Cat is an animal, that doesn't mean Dog is a Cat. Why do you think IOException extends BusinessException?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just use the JavaDocs for java.io.IOException to understand your problem.

If you are going to be a Java Programmer you need to get very familiar with the JavaDocs.

Bill
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Naik wrote:In my below code, BusinessException is subclass of Exception.
IOException is subclass of Exception that means IOException is also a subclass of BusinessException ...


No.

Suppose Exception is your father.

You are BusinessException, you inherit from your father, Exception.

You also have a brother, IOException, that also inherits from your father, Exception.

But just because you and your brother are both subclasses of Exception, it does not mean that your brother IOException also is a subclass of you, BusinessException. You are not the father of your brother.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cant believe I asked this question. I think it's an effect of loooong working hour.

Anyways thanks a lot everybody, My concept on Exception hierarchy and inheritance is now clear.

@Bill
Will surely get familiar with Java Doc very soon.

Cheers !!
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic