If you are really wedded to this architecture (and it's not really that
bad) then a good approach could be something like:

Public class myServlet extends HttpServlet {
doGet(HttpServletRequest req, HttpServletResponse res) {

        try {
                // All servlet code happens between this try catch pair.
                //
                // Beginning of servlet
                MyClass.invokeSubRoutine();

                // End of Servlet
        } catch (ProcessingInterruptedException PIE){
                return;
        } finally {
        }

}
}

Public class MyClass {

public static int invokeSubRoutine() 
throws ProcessingInterruptedException {
        ProcessingInterruptedException pieThrow=null;


        try {
                // Some JDBC Code
        } catch (SQLException se) {
                // Log it
                // Send Redirect
                pieThrow=new ProcessingInterruptedException();
                // Alternatively
                throw new ProcessingInterruptedException();
        }

        if (pieThrow!=null){
                throw pieThrow;
        }
        return retVal;
        }

}

This code is somewhat cleaner because it forces the caller to handle the
exception. In general, the idea behind exceptions is that nobody checks
return codes so let's use the compiler to force them to catch an error.

George Sexton
MH Software, Inc.
Home of Connect Daily Web Calendar Software
http://www.mhsoftware.com/connectdaily.htm
Voice: 303 438 9585

-----Original Message-----
From: Merrill Cornish [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 02, 2004 1:00 PM
To: Tomcat Users List
Subject: Re: How is catch{} code handled


George,

>Unfortunately, your logic is flawed.
>  
>
Yes, that's very clear at this point.  :-)

I understand that the sendRedirect() does NOT terminate the execution 
flow that it is in.  That's why I follow each one with a return. 
However, I think I now recognize my problem.

In my mind, I've always associated a catch{} with an exception and 
nothing "escapes" from the exception.  And that's true, assuming you did

NOT do what I did and disolve the exception into a simple message that 
displayed as text on a JSP page.  As I now see, in THAT case, the 
catch{} DOES return, thereby allowing multiple sendRedirect()s to
occurs.

Thank you for setting my thinking straight.

Merrill

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to