[patch] Java definite assignment

Per Bothner per@bothner.com
Tue Feb 6 16:53:00 GMT 2001

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?

No.  It's a 'finally', not a 'catch'.  The 'finally' clause will
catch all exceptions, execute the clause and *re-throw* the exception.

try-finally is Java syntax for unwind-protect, if that helps.
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

More information about the Java mailing list