Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clear this question in StudyKit

 
GuanXing Fung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code in the chapter "Handling server-side
exceptions":
public void doGet(HttpServletRequest req,
HttpServletResponse res)
{
String category = req.getParameter("category");
if( !loggedIn(req) )
{
//Set the status code to 403 if the user is not logged in.
//we may also use setStatus().
res.sendError(res.SC_FORBIDDEN);
return;
}
Vector items = new Vector();
try
{
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"select * from ITEM where CATEGORY=' "+category+"' "
);
while(rs.next())
{
items.addElement(rs.getString("name"));
}
}
catch(SQLException e)
{
//wrap the exception in a ServletException and rethrow
throw new ServletException("Wrapped SQLException", e);
}
}
my question is :Why the doGet() method didn't need "thows" clause because there is "throw" in the catch block and not catch the Exception in outside?
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that might be a one of the errors in errata.
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several of the code examples in the SCWCD Study Kit omit the ServletException and IOException in the throws clause of the doXXX methods.
Might be errata, or an assumption that it would be taken as read.
 
GuanXing Fung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic