aspose file tools
The moose likes Beginning Java and the fly likes Servelt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 56162
    
  13

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Servelt