• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Servelt

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me in overriding why we can not throw broder exception
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Sheriff
Posts: 67265
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21758
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!