Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding Exceptions

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted something on this HERE the other day. See if that helps.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic