• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servelt

 
parag dandegaonkar
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
 
Sebastian Janisch
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.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java 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