aspose file tools*
The moose likes Beginning Java and the fly likes Servelt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Servelt" Watch "Servelt" New topic
Author

Servelt

parag dandegaonkar
Greenhorn

Joined: Jan 30, 2009
Posts: 7
please tell me in overriding why we can not throw broder exception

SCJP5,SCWCD5
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Hey,

first, please choose a meaningful title for your topic, as it's pretty obvious that it's about servlets if it's posted in the Servlets forum ;-)

Your question is more about Java in general. When overriding your method you may throw lesser, narrower, or no exceptions compared to the super class method. Having said that it is not possible to throw a broader exception in a servlet.

What you can do however is chain an exception meaning wrapping it in a servlet exception. That's common practice and looks like this.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

parag dandegaonkar wrote: please tell me in overriding why we can not throw broder exception

Because calling code will not expect it. Consider this example:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Servelt