You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cesar Arevalo <ce...@yahoo.com> on 2007/10/01 22:20:29 UTC

[OT] Re: A try catch and return question

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.)" <lz...@ford.com>
To: Struts Users Mailing List <us...@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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org