The blocks you mention achieve different results. In the FIRST block you will 
have to add a return statement for when an exception is thrown, this allows you 
to set the theReturnedObject to a value for when an exception is thrown. In the 
SECOND block if you are modifying theReturnedObject in the try block then you 
will have to take into account that an exception might occur and that this 
exception might affect the value of theReturnedObject.

Oh and by the way, this is a struts mailing list :-)

HTH
-Cesar

----- Original Message ----
From: "Zhang, Larry (L.)" <[EMAIL PROTECTED]>
To: Struts Users Mailing List <user@struts.apache.org>
Sent: Monday, October 1, 2007 1:01:23 PM
Subject: A try catch and return question

I have a method having the following structure:

public Object myMethod() {
    try {
    // some code
    return theReturnedObject,
    }catch{
         // some code
    }
    finally {
     // some code
    }
}
 
Please let me know if the following version of code better than the
above?
public Object myMethod() {
    try {
    // some code
    
    }catch{
         // some code
    }
    finally {
     // some code
    }

    return theReturnedObject,
}

The only difference is that the bottom one put the return down to the
bottom of the method and take the return out of the try. Please let me
know.

---------------------------------------------------------------------
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