tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig Berry" <Craig.Be...@portblue.com>
Subject RE: How is catch{} code handled
Date Fri, 02 Jan 2004 19:42:56 GMT
Merrill Cornish [mailto:merrill.cornish@earthlink.net] wrote...

> Why did main servlet processing appear to continue (allowing the
> second sendRedirect() to cause a problem) after the exception was
> triggered?

Processing of a catch block does not terminate processing of the surrounding method.  In other
words, in this code fragment
 
  try {
    foo.callMethodThrowingFooException();
  }
  catch (FooException fe) {
    System.out.println("Caught a FooException");
  }
  System.out.println("After try/catch block");
 
if a FooException if thrown, control flows to the catch block, but then drops out to the following
code normally.  This is a useful Java language feature for dealing with locally-recoverable
errors.
 
If you want method processing to stop, you have to throw a new exception, return from inside
the catch block, add logic suppressing further processing triggered by a flag set in the catch
block, or otherwise explicitly avoid executing the remainder of the method.
 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message