It's not a secret anymore!
The moose likes Beginning Java and the fly likes regarding Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "regarding Exceptions" Watch "regarding Exceptions" New topic

regarding Exceptions

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
A subclass cannot throw more checked exceptions that its superclass,why??
Any performance issues or what is the reason??
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I posted something on this HERE the other day. See if that helps.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
Hi Stan,
Thanks for providing the link.In this link i have one doubt.

And what if somebody passed an instance of B into my method? I'd be totally unprepared to handle a SQLException because A never told me it might happen.

If something happens in class B,B should take care of it.Why should it rely on class A.
Please clear the doubt.
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
If B takes care of the SQLException, then there is no problem, because the method will no longer throw a SQLException. Stan's example was showing the problem with the method throwing a broader exception than declared in the parent class.
[ August 01, 2007: Message edited by: Joanne Neal ]

I agree. Here's the link:
subject: regarding Exceptions
It's not a secret anymore!