• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

clear this question in StudyKit

 
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?
 
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.
 
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!
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic