• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServlet question

 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code can work:
public class sampleServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
req.getSession().setAttribute("userid", userid);
}
}
my question is that
since doXXX(HttpServletRequest req, HttpServletResponse res) throws ServletException in HttpServlet, why doesn't the doPost of sampleServlet need to catch ServletException or to throw it
 
Barry Kushnir
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timber,
This really has nothing to do with servlets, per se. When you extend a class and override a method, Java insists that the new method cannot be declared as throwing checked exceptions of classes other than those that were declared by the original method. However, It may throw exceptions derived from the base-class exceptions, some of the base-class exceptions, or none of them at all.
-BK
 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank Barry Kushnir
[ October 14, 2002: Message edited by: timber lee ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic