This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] Java definite assignment


On 06-Feb-2001, Per Bothner <per@bothner.com> wrote:
> Fergus Henderson <fjh@cs.mu.oz.au> writes:
> 
> > >       String x; try { x = new String (); } finally {} x.toString ();
> > 
> > Surely it *should* issue an error message in that case.
> > If `new String ()' throws an exception (e.g. because we're
> > out of memory), then `x' will never get explicitly initialized.
> 
> But the x.toString() will never get executed either, so it doesn't
> matter.  I.e. we will never execute code that accesses x without
> x having been assigned first.

I think one of us is missing something.  I didn't get much sleep last
night, and I've only had one cup of coffee this morning, so maybe I'm
still asleep, in which case it is probably me ;-)
But I don't see why `x.toString()' will never get executed.  If the
exception is thrown, the `try {...}' will catch it, and then execution
will continue at `x.toString()', won't it?

Perhaps it helps if I add some more whitespace to the example:

       String x;
       try {
          x = new String ();
       } finally {
          /* do nothing */
       } 
       x.toString ();

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]