File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Servelt" Watch "Servelt" New topic


parag dandegaonkar

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

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183

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

Joined: Jan 10, 2002
Posts: 61961

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

Joined: Oct 27, 2005
Posts: 19844

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:

How To Ask Questions How To Answer Questions
subject: Servelt