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(..).
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?
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 ...
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.