For clarification, I think Vyas was pointing out that if a method
throws an exception, the method that _calls_ it must be explicitly
prepared to catch it. In Sam's code, whatever calls doGet or doPost,
whether from inside the class 'newlite' or not, has to be prepared to
catch both a ServletException and an IOException.
On Fri, 26 Feb 1999, Milt Epstein wrote:
> On Fri, 26 Feb 1999, Vyas Vemu wrote:
>
> > if you 'throw' a particular exception in your class declaration, you
> > must also specifically 'catch' it..
>
> Not sure if there's a "not" missing here, but as stated, this is
> incorrect. If you catch a particular exception within a method, it
> doesn't make sense to declare that method as throwing it, since that
> will never happen (assuming you catch all possible places where that
> exception could occur and you don't specifically throw it elsewhere).
> I'm not sure there's any harm in doing so (I don't think the compiler
> will complain), there's just no point in doing so. Usually you either
> do one or the other, i.e. catch it locally and handle it, or not do
> anything and have it passed back up the calling stack.
>
>
> > Sam Rose wrote:
> >
[snip]
> > >
> > > public class newlite extends HttpServlet {
> > >
> > > public void dostuff (HttpServletRequest req, HttpServletResponse res)
> > > throws SQLException, ServletException, IOException {
> > >
> > > HttpSession tsession=req.getSession(true);
> > > res.setContentType("text/html");
> > > PrintWriter os=res.getWriter();
> > >
> > > try { Class.forName( "oracle.jdbc.driver.OracleDriver" );
> > > os.println("<p>");
> > > }
> > > catch (java.lang.ClassNotFoundException e) {
> > > os.print("ClassNotFound: ");
> > > os.println(e.getMessage());
> > > }
> > > try {
> > > con = DriverManager.getConnection();
> > > stmt = con.createStatement();
> > >
> > > }//endtry
> > >
> > > catch (java.sql.SQLException ex) {
> > > os.println("SQLExcption: " + ex.getMessage());
> > > }//endcatch
> > >
> > > finally {
> > > if (con != null) {
> > > con.close(); }//endif
> > > if (stmt != null) {
> > > stmt.close();}//endif
> > > }//endfinally
> > >
> > > }//end dostuff
> > >
> > > public void doGet (HttpServletRequest req, HttpServletResponse res)
> > > throws ServletException, IOException {
> > > dostuff(req, res);
> > > }
> > >
> > > public void doPost (HttpServletRequest req, HttpServletResponse res)
> > > throws ServletException, IOException {
> > > dostuff(req, res);
> > > }
> > > }//end
Corey Feder
Columbia University
Please ignore the things that come out of my mouth. I'm a student; I'm
trained to speak as if I know what I'm talking about, especially when I
don't.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html