Return from a method at the end of a thread

Hi all,
I've written a slideshow in a class implementing Runnable, overriding the run() method.
I want that my a method "startSlideShow()" returns when the task of the thread ends (the thread mainly display images).
I've tried the the join() method (see code below) but the displaying of the images doesn't occurs any more.
public class SlideShow extends JPanel implements Runnable {
    //The  main thread to run the slideshow
    Thread slideShowThread = new Thread(this);
     * Launch the slideshow
    public void startSlideShow() {
        //launch the slide show
        slideShowThread.start();
        //build and launch the listening of the end of the slideshow
        //prob : it freeze the displaying
       try {
            slideShowThread.join();
            System.err.println(" thread ENDED");
        } catch (InterruptedException ex) {
            System.err.println(ex+" thread was stopped");
        //this method SHOULD returns when the slideshow ended
public void run(){
//here is the slideshow code...
}I've tried several other piece of code but I didn't succeed to makes my startSlideShow() method returns when the run() method end.
Could you help ?
thank you

SlideShow slideShow = new SlideShow();
slideShow.setCompletionListener(new
ew CompletionListener() {
public void executionComplete(SlideShow source) {
//Execution will continue here when slideshow is
w is complete...
          Thread t = new Thread(slideShow);
          t.start();
/Kajok, thank you a lot for this. This fit my needs as the parent class of slideshow shouldn't be of a specific structure now. I will use this technic.
However, just a general remark about the threads and my wish to have a modal function.
You said that :
"As I told you, you should never ever block the AWT thread so you can't make it modal. UI programming is event driven.
and I agree. the point is that I wanted to do something like the JOptionPane set at modal.
Let's consider the jOptionPane as a metaphor (I don't want to implement my slideshow using optionPane, obviously...)
When we call a jOptionPane, we wait for an user action, then the jOptionPane returns (usually returning the results of the user action) :
value = JOptionPane.showOptionDialog(
                    contentPane,
                    "my question is",
                    "my title",
                    JOptionPane.YES_NO_OPTION, // need answer
                    JOptionPane.QUESTION_MESSAGE,
                    null, // default icon for message type
                    options,
                    options[1]); //default selected value);So I was thinking that it should have been possible make a class which display the slideshow and then retunrs, after a specific event, which is the end of the slideshow...like the structure of the JOptionPane do.
Thank for your useful answers,

Similar Messages

  • Problem with image returned from getGeneratedMapImage method

    I'm a newbie as far as map viewer and Java 2D goes....
    My problem is the java.awt.Image returned from the getGeneratedMapImage method of the MapViewer API. The image format is set to FORMAT_RAW_COMPRESSED. The image returned is of poor quality with colors not being correct and lines missing. I'm painting the Image returned from this method onto my own custom JComponent by overriding the paint() method...
    public void paint( Graphics g )
    Image image = map.getGeneratedMapImage();
    if ( image != null )
    g.drawImage( image, getLocation().x, getLocation().y, Color.white, this );
    If I take the xml request sent to the application server and paste it into a "sample map request" on the map admin website (along with changing format to PNG_STREAM) my image renders exactly how I expect it to.
    Anyone have any idea what I need to do to get the java.awt.Image with format set to FORMAT_RAW_COMPRESSED to render correctly. I was hoping to get back a BufferedImage or a RenderedImage from the getGeneratedMapImage call but I'm getting back a "sun.awt.motif.X11Image".
    Will downloading the JAI (java advanced imaging) from sun help me at all?

    Joao,
    Turns out it is related to colors. I'm dynamically adding themes, linear features and line styles. I ran a test where I changed the color being specified in the line style from magenta (ff00ff) to black. When I changed the color the linear feature would show up. It was being rendered as white on a white background when I was specifying it to be magenta. I'm specifying another linear feature to be green and it is showing up in the java image as yellow. This doesn't happen when I take the generated XML from the request and display it as a PNG_STREAM.
    Any clue what is going on there?
    Jen

  • Is there a way to prevent Robohelp WebHelp from appending characters to the end of the URL address for a TOC Entry?

    I am running RoboHelp 10 on Windows 7 Enterprise SP1 64 bit OS.
    WebHelp is appending characters to the end of the TOC entry's URL address. The characters "bc-n" where n is a number are being generated for all of the TOC Page Entries when I generate WebHelp output. We are exporting the HTML files for import into an application. The TOC Page Properties Link to: property does not contain the characters in RoboHelp.
    We have standardized names defined for our application and the appended characters are not going to work in the application.
    cid:[email protected]
    When I use the generated html output in IE10 Version 10.0.9200.16635 Update Versions: 10.0.7 (KB2846071) the characters show up in the URL when I hover the mouse over the TOC entry as shown in the screenshot below.
    cid:[email protected]
    The two screenshots show that the Link to property does not have the characters "bc-7" but the URL address does.
    Is there a setting or way to configure RoboHelp to prevent Robohelp WebHelp from generating and appending characters to the end of the URL address for TOC Entries?

    I have never known Rh add any characters so I think something else is at play here. Please open one of the sample projects and see what happens there. Click Open on the RoboHelp Starter page and then click Samples in the ribbon on the left.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • How-To Display the Number of Records Returned from a List to the User?

    We currently are using lists to identify accounts that meet various criteria. Because the territories vary from 4k to 60k customers the users have stated that they don't know the size of the list and therefore don't know if they need to refine the list. Currently they are exporting to Excel to look at the row count to see if they need to further refine their searches. This takes quite a while and while shuffling through many lists is a bit painful. Isn't there a way to just show the total records returned from the list down at the bottom of the screen where it allows you to see 25/50/75/100 records at a time?
    There is probably a simple way to do this but it is a large user dissatisfier at the time because we simply don't know how to make this show up. Again we are using lists and not analytics for simple lists at this time.
    - john
    Edited by: user11286597 on Jun 19, 2009 11:02 AM

    Thanks Bobb. I can't believe that one wasn't in R1 :)
    Is there a link to the items being worked in the next release by any chance?
    - john

  • Every time I download app from AppStore but at the end it couldn't download. Not all time but sometime this problem occurre ! I have to retry the app for 3-4 times and after that it downloaded in iphone

    i have a iphone 6 . From the last 2-3 weeks i have seen some proble in my iphone that I Couldn't download any app or update any app in my appstore. Every time it shows at the end that youe app can not download ! But after retry and retry i can download that app.! So can you help me ! is there any problem in my iphone6 ?

    You must have a separate Apple ID registered in the other store along with a valid bank-issued charge card in the other country, and a legal billing address in the other country.
    Sorry... But... You cannot use other countries itunes stores.
    You must be within the Country with a Valid Billing Address and Credit Card for that Country to use the iTunes Store of that Country..
    iTunes Store Terms of Service
    http://www.apple.com/legal/itunes/us/terms.html#SERVICE

  • Return from String method

    Hi
    Can anyone help me:
    I have a class with a String method.
    The returned value for the method is calculated in a thread. Since I have to share the same literal for the String and run methods, the returned value for the String method is not the value that the run method is supposed to calculate for me. It just wouldn't wait until it's ready.
    What should I do? Can I block the String method to return the string until the run method is ready?

    Look up Thread.waitFor()

  • Return from a method

    public class A
    static String str="";
    public static void set(String temp)
    str=temp;
    public static String get()
    return str;
    // i want to set the value of str="" after return ?
    How to set the value of a variable to "" after it returns

    public class A
    static String str="";
    public static void set(String temp)
    str=temp;
    public static String get()
    return str;
    // i want to set the value of str="" after return ?
    How to set the value of a variable to "" after it
    returns
    public static String get() {
        try {
            return str;
        } finally {
            str = "";
    }this works but I find it a bit awkward... why do you need such a thing ? why can't you call set("") afterwards instead ?

  • How to get string which is return from a method and method is called from a filter

    Can anyone please guide me how i will get a string on a template, this string value is return by method which is called through 'ValidateStandered' filter.
    My problem is when i CheckIn a document, i am implementing some validation of duplicated document and duplicated document is identified by some metadata value.
    if metadata value of CheckIn document(current document) is same with existing document then filter will return ddocname and ddoctitle of existing document on a template(user can see the ddocname of existing item).

    please find error logs also:
    intradoc.data.DataException: !csDbCouldNotBind,getValueOfDuplicateDocument
            at intradoc.jdbc.JdbcQueryUtils.buildQuery(JdbcQueryUtils.java:107)
            at intradoc.jdbc.JdbcWorkspace.buildQuery(JdbcWorkspace.java:736)
            at intradoc.jdbc.JdbcWorkspace.createResultSet(JdbcWorkspace.java:639)
            at CheckInRestrictionFilter.CheckInRestrictionFilter.getResultSet(CheckInRestrictionFilter.java:108)
            at CheckInRestrictionFilter.CheckInRestrictionFilter.doFilter(CheckInRestrictionFilter.java:57)
            at intradoc.shared.PluginFilters.filterWithAction(PluginFilters.java:114)
            at intradoc.shared.PluginFilters.filter(PluginFilters.java:68)
            at intradoc.server.DocServiceHandler.validateStandard(DocServiceHandler.java:1251)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:86)
            at intradoc.common.ClassHelperUtils.executeMethodReportStatus(ClassHelperUtils.java:324)
            at intradoc.server.ServiceHandler.executeAction(ServiceHandler.java:79)
            at intradoc.server.Service.doCodeEx(Service.java:620)
            at intradoc.server.Service.doCode(Service.java:592)
            at intradoc.server.ServiceRequestImplementor.doAction(ServiceRequestImplementor.java:1693)
            at intradoc.server.Service.doAction(Service.java:564)
            at intradoc.server.ServiceRequestImplementor.doActions(ServiceRequestImplementor.java:1483)
            at intradoc.server.Service.doActions(Service.java:559)
            at intradoc.server.ServiceRequestImplementor.executeSubServiceCode(ServiceRequestImplementor.java:1346)
            at intradoc.server.Service.executeSubServiceCode(Service.java:4109)
            at intradoc.server.ServiceRequestImplementor.executeServiceEx(ServiceRequestImplementor.java:1222)
            at intradoc.server.Service.executeServiceEx(Service.java:4104)
            at intradoc.server.Service.executeService(Service.java:4088)
            at intradoc.server.Service.doSubService(Service.java:3998)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:86)
            at intradoc.common.ClassHelperUtils.executeMethodEx(ClassHelperUtils.java:310)
            at intradoc.common.ClassHelperUtils.executeMethod(ClassHelperUtils.java:295)
            at intradoc.server.Service.doCodeEx(Service.java:637)
            at intradoc.server.Service.doCode(Service.java:592)
            at intradoc.server.ServiceRequestImplementor.doAction(ServiceRequestImplementor.java:1693)
            at intradoc.server.Service.doAction(Service.java:564)
            at intradoc.server.Service.doScriptableAction(Service.java:4050)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at intradoc.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:86)
            at intradoc.common.ClassHelperUtils.executeMethodEx(ClassHelperUtils.java:310)
            at intradoc.common.ClassHelperUtils.executeMethod(ClassHelperUtils.java:295)
            at intradoc.server.Service.doCodeEx(Service.java:637)
            at intradoc.server.Service.doCode(Service.java:592)
            at intradoc.server.ServiceRequestImplementor.doAction(ServiceRequestImplementor.java:1693)
            at intradoc.server.Service.doAction(Service.java:564)
            at intradoc.server.ServiceRequestImplementor.doActions(ServiceRequestImplementor.java:1483)
            at intradoc.server.Service.doActions(Service.java:559)
            at intradoc.server.ServiceRequestImplementor.executeActions(ServiceRequestImplementor.java:1415)
            at intradoc.server.Service.executeActions(Service.java:545)
            at intradoc.server.ServiceRequestImplementor.doRequest(ServiceRequestImplementor.java:751)
            at intradoc.server.Service.doRequest(Service.java:1974)
            at intradoc.server.ServiceManager.processCommand(ServiceManager.java:486)
            at intradoc.server.IdcServerThread.processRequest(IdcServerThread.java:265)
            at intradoc.idcwls.IdcServletRequestUtils.doRequest(IdcServletRequestUtils.java:1355)
            at intradoc.idcwls.IdcServletRequestUtils.processFilterEvent(IdcServletRequestUtils.java:1732)
            at intradoc.idcwls.IdcIntegrateWrapper.processFilterEvent(IdcIntegrateWrapper.java:223)
            at sun.reflect.GeneratedMethodAccessor130.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at idcservlet.common.IdcMethodHolder.invokeMethod(IdcMethodHolder.java:87)
            at idcservlet.common.ClassHelperUtils.executeMethodEx(ClassHelperUtils.java:305)
            at idcservlet.common.ClassHelperUtils.executeMethodWithArgs(ClassHelperUtils.java:278)
            at idcservlet.ServletUtils.executeContentServerIntegrateMethodOnConfig(ServletUtils.java:1680)
            at idcservlet.IdcFilter.doFilter(IdcFilter.java:457)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
            at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
            at java.security.AccessController.doPrivileged(Native Method)
            at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:324)
            at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
            at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
            at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
            at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
            at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:163)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
            at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
            at java.security.AccessController.doPrivileged(Native Method)
            at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:324)
            at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
            at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
            at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
            at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3739)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3705)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
            at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2282)
            at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2181)
            at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1491)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

  • Aggregator: Setting up navigation from one SWF to the end of a previous SWF.

    If anyone has a strategy that has worked for them, please let me know. In the mean-time, I'll try an idea I have that employs a main swf to hold variables and set those variables with navigation buttons. For example, if the back button is clicked, I can set a variable indicating the target location for the previous file is the last page. I can use a conditional statement on the first slide.
    I'll let you know.
    Thomas

    I'm beginning to wonder if I am misunderstanding the purpose of aggregator. I always try to keep .swf files small. I planned to use aggregator to host variables from subordinate swf files. The Adobe help file at http://help.adobe.com/en_US/captivate/cp/using/W8c1b83f70210cd101-1ff8d6a911d0a0500a3-8000 .html seems to suggest a different vision. If the aggregator's only function is to combine multiple swfs into one giant swf, then clearly the author of Flash's scenes has escaped the asylum.

  • How do I keep a completed video from running on past the end, showing black screen?

    My completed Premiere Elements 9 video does not end where it should, it runs on for another five minutes - showing black screen. Do I need to place an end marker to stop the video or change a setting? This has not happened on other videos I've created.

    Steve,
    You were right. There was a straggler lurking out there. I deleted it and was able to get the Work Area Bar to snap back to the correct video length.
    Thanks!
    Christopher J. Klein
    Marketing Coordinator
    1702 West Washington Street – South Bend, IN 46628 USA
    Phone: +1 (574) 233-9490, Ext. 245
    Facsimile: (574) 233-9489
    [email protected]<mailto:[email protected]>
    www.mtiwelding.com<http://www.mtiwelding.com/>
    Manufacturing Technology, Inc.
    Solid-State Joining & Welding Solutions, Equipment & Services
    DIRECT DRIVE   —   INERTIA   —   LINEAR   —   STIR   —   RADIAL   —   RESISTANCE
    THIS DOCUMENT AND ALL INFORMATION HEREON CONSTITUTE CONFIDENTIAL AND PROPRIETARY property of mtI. Any disclosure, transmission, copying, altering or modifying of this DOCUMENT or any information hereon without written PERMISSION OF MTI IS EXPRESSLY PROHIBITED. THIS PARAGRAPH SHALL APPLY REGARDLESS OF ANY AGREEMENT, PURCHASE ORDER OR OTHER WRITING OR DOCUMENTATION TO THE CONTRARY.
    cid:[email protected]

  • Download a file after the end of a Thread

    Hi everyone,
    I post here because I have a problem with a part of my application in ADF.
    In my page I have a button witch create a Thread ans in this Thread I create a file. I checked if the Thread is alive or not with a poll and a progressIndicator.
    When the Thread end I want to show a download pop up to download the file witch is create by the Thread. But nothing appends. A friends tell me to create a button, put the download code in the action and fire the button with code. But I have the same result.
    If I click on the button everything is fine but with the code nothing appends.
    this is the method I use to check if the Thread is alive :
    public boolean isCreateReportRunning(){
    if(createReportThread == null){
    poll.setTimeout(60000);
    return false;
    if(!createReportThread.isAlive()){
    try {
    System.out.println("CreateReportThread is not alive - Thread is free");
    createReportThread = null;
    poll.setTimeout(0);
    refreshCurrentPage();
    //Fire the button with code
    new ActionEvent(hiddenButton).queue();
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    return true;
    In the action I simply show the pop-up to download the file
    This is for the hidden button in my jspx page :
    <af:commandButton text="Download" id="cb1"
    binding="#{reportV2Bean.hiddenButton}"
    action="#{reportV2Bean.hiddenButtonClick}"
    immediate="true" partialSubmit="true">
    </af:commandButton>
    I also try with a <af:fileDownloadActionListener> but the problem also occurred
    Thank you for your help.
    Lish
    Edited by: Lish on May 9, 2011 4:58 AM

    Noboby has an idea about my problem ?

  • Running different set of methods on the same class via threads

    Hello all,
    I have this issue that I am trying to deal with. It looks pretty simple to me, but maybe just a mental block I guess :)
    Now the code below will give you an idea of what I am trying to achieve. I am not sure if its possible or if there is some other better way to do this. Any help will be appreciated.
    Thanks
    public class TestClass extends Thread{
         public TestClass(){
         // Assume something goes in here.
         public void abc(){
              System.out.println("In abc");
         public void xyz(){
              System.out.println("In xyz");
         public void run(){
         //What do I put here, since my call is specific.
         public static void main(String args[]){
              TestClass t1 = new TestClass();
              t1.start();// I want t1 to call only abc()
              TestClass t2 = new TestClass();
              t2.start();// I want t2 to call only xyz
    }Edited by: mikkin on Mar 12, 2009 3:00 PM

    kogose wrote:
    you can use the Reflection API to make the desired method an instance variable:Whoa, that's a pretty big case of over-engineering (or under-engineering, depending on how you look at it) and abuse of Reflection. The real problem in the original post is that Thread isn't being used properly. You almost never want to subclass Thread, for reasons like these: your runnable target should be separate from the thread. I would organize your code like this:
    public class TestClass {
       public TestClass() {
          // Assume something goes in here.
       public void abc() {
          System.out.println("In abc");
       public void xyz() {
          System.out.println("In xyz");
       public static void main(String args[]) {
          final TestClass t1 = new TestClass();
          final TestClass t2 = new TestClass();
          new Thread(new Runnable() {
             public void run() { t1.abc(); }
          }, "t1Thread").start();
          new Thread(new Runnable() {
             public void run() { t2.xyz(); }
          }, "t2Thread").start();                   
       }

  • The problem of return value from a method

    Hi everyone:
    I want return a value from following method. The basic idea is that I want use Num as a parameter to get a value from a field, therefore I can input this value into another database for the display purpose by using other classes. However I got error message when I compiled it.
    "method does not return a value"
    I know it is a problem, but how I can fix it? I need your help. Thanks in advance.
    Dawei
    Method:
    public int Read(int Num) {
    try{
    String qr1 = "select Record form Buffer where Record="+Num+"";
    ResultSet rs = statement.executeQuery(qr1);
    while (!rs.next()){
              int result=rs.getInt(1);
    return(result);
         catch (SQLException e){
                   System.err.println("Error in inserting into database " + e);
                        System.exit(1);
    return 1;

    "select Record form Buffer ...Hopefully "form" is actually "from" in your code.
    You have three points of exit from your routine, and only two return value statements.
    1 -Return inside the while loop has a value.
    2- Return inside the exception block (not sure that '1' would be a valid number)
    3- The very end of the method, just before the last '}' does not have a return statement.
    By the way, this question has nothing to do with JDBC, so another forum might be a better place to post it.

  • Return statement at the end of try or after catch blocks

    Hi
    Can anyone tell me which is the better practice - to put the return statement at the end of try block or after all the catch blocks ie at the end of method.
    Eg
    Method A()
    String str;
    try{
    str= [some code]
    return str
    catch(Exception e)
    System.out.println("Exception");
    } // end of method
    OR
    Method B()
    String str;
    try{
    str= [some code]
    }catch(Exception e)
    System.out.println("Exception");
    return str
    } // end of method

    I always try to work with only one exit point for each method.
    For readability I always put the return statement as close to the end of the method as possible.
    In this particular question,
    I think you should put the return at the end of the method (for readability, since this is what you are
    familiar with), but when I have a try-catch clause, I usually have an unrecoverable error and
    should throw this further down the tree, so it usually becomes
    try{
       return   
    }catch(...){
       // write out some logging information
       rethrow exception or throw another exception
    }I think you should NEVER reflect the occurence of an error in the return-value of the
    method when an unrecoverable exception occurs. Just rethrow this exception or throw another method.
    Other methods look like
       Object result = new...
       return result;As for the specific case of a repetitive if-case:
    This is possible in two versions:
    With one return and a result-object
    Object result = new ...
    if(..)
       result = ...
    else if(..)
       result = ...
    return result;With every time a return
    if(...)
       return ...;
    else if(...)
       return ...;For me the above two possibilities make no difference,
    but I find the second version (which I hated when I began programming)
    to be somewhat more of a (self-made) standard nowadays.
    But I do not think this particular case makes much of a difference.
    kind regards,

  • More the 1 return in a method, Good or Bad?

    Hello, quick question. Is it bad programming, and maybe even dangerous to have more that 1 return in a class. for example which of these code would be correct?
    int value = 0;
    if(one==true)
    value = 1;
    else if(two==true)
    value = 2;
    else if(three==true)
    value = 3;
    else if(four==true)
    value = 4;
    else if(five==true)
    value = 5;
    return retValue;
    ------------------------OR
    f(one==true)
    return 1;
    else if(two==true)
    return 2;
    else if(three==true)
    return 3;
    else if(four==true)
    return 4;
    else if(five==true)
    return 5;

    As a general rule, yes. Returning a value from the
    middle of a for-loop inside an if-statement would not
    be good style. But I do find myself writing methods
    that get the trivial cases out of the way first,
    before getting into the real code.
    Example:public String extractNames(NodeObject
    node) {
    if (node == null) return null;
    // complex code follows on here
    I agree with you in practice and in general. In fact, I also do the same thing although I would throw in a comment like //exit method if no valid processing possible due to null parameter or just invoke another method to do the complex logic part and have a member variable that is null or what is returned from the complex logic method.
    I try to have one return for several reasons :
    1) as listed above - for ease of debugging
    2) multiple returns reminds me of the code that used "goto exit" to get out of a loop because the programmer could not figure out any better way to get out without overly complex code.
    3) standards of only one point of entry and exit from a method.
    The only reason I can see for the complex code not to be in another method (at least in the simple example above) would be for performance reasons.

Maybe you are looking for

  • Excise invoice in INR and Billing document in EURO.development issue.

    Dear All its  intersesting development i came accross please help if u have came accross this before. in my scenario i am having a  client who placed an order from Europe and the currency is in EURO  and we have to deliver it to a client who is in in

  • Itunes 7 won't show songs when Ipod is plugged in.

    I used to just plug in my ipod on the old Itunes, click on the "manage manually" button and be able to look at and play (through my computer) all of the songs on my IPOD (My home computer is a separate laptop) So I downloaded Itunes 7 and when I plug

  • White borders introduced during export?

    Aperture seems to be randomly adding whire borders to only some of my images during export. Of two nearly identical images, one has them, the other does not. Look at these examples: http://www.reesweb.com/samples/border/ These images are both portion

  • Report on Position and the corresponding Job

    Dear Friends, There were some positions which are wrongly assigned to some Jobs. For e.g.: an Account Superintendent position is assigned to a Stenographer Job. So we would like to find out which position is assigned to which job. Is there any report

  • Nice basic explanation of curves vs. levels

    http://www.photographlondon.co.uk/curves.htm