• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

clear this question in StudyKit

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that might be a one of the errors in errata.
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you very much!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic