Re: compiler warning



Thomas G. Marshall wrote:
Patricia Shanahan coughed up:

And I'm not convinced that it is a particularly useful restriction worthy of any hissy fit ;) from the compiler engineers at sun. Save for a minor slap in the face to the structured programming zealots (which I condone anyway), I just don't see the problem.

Then I don't think you are looking hard enough.

Take this method:

public int foo() throws Exception
{
    try
    {
        bar();
        return 1;
    }
    catch( IOException e )
    {
        return 2;
    }
    finally
    {
        return 3;
    }
}

Quick, without thinking too hard about it, what happens in these cases:

- bar completes normally
- bar throws an IOException
- bar throws an exception other IOException

While you a seasoned veteran probably can figure out the answers don't you think the fact that it returns 3 in all cases might be confusing to a newbie?

If there were a valid use case for having a return statement in a finally block then there might be a reason to not have the warning.

Since there isn't a good use case for it and the behavior will be confusing to newbies and possibly cause undesirable behavior then it is a good idea to warn people.

--
 Dale King
.



Relevant Pages

  • Start Up question
    ... looked in the init.d and rc.d directorys but it is just confusing to ... I am a newbie just getting to grips with RH Please Help. ...
    (linux.redhat)
  • Re: finding the position of an element in a "list of strings"
    ... book about Common Lisp than the Reference. ... i am not a *pure* newbie, i already did 22 chapters from PCL, very ... complex & confusing & in the end i made it. ...
    (comp.lang.lisp)
  • Re: how to write the following script
    ... >> You forget how very mysterius and confusing these things can be to a newbie. ... > understand how to fish, then you throw the fish at them. ...
    (comp.unix.questions)
  • Re: earthquake forecast calendar maps
    ... caryrjr@xxxxxxxxxxxxxxxx wrote: ... >>> I'm a newbie here. ... >> All I see is a bunch of green and red squares corresponding to ... but think how confusing it will be to somebody who knows nothing about ...
    (sci.geo.earthquakes)