tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "George Sexton" <>
Subject RE: How is catch{} code handled
Date Fri, 02 Jan 2004 21:10:19 GMT
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

		// End of Servlet
	} catch (ProcessingInterruptedException PIE){
	} 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
Voice: 303 438 9585

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


>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

Thank you for setting my thinking straight.


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message