Re: try...catch and local variables
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 22 Nov 2006 20:28:11 -0000
Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote:
<snip>
I wonder if the compiler/framework will barf on that too? :) Most
likely...
That is more like the compiler bug I was talking about. I haven't tried
that exact construct, but I have written code where it is provable that the
variable *is* initialized prior to access, and yet the compiler complains
that it isn't. In these cases (such as your example, and the other examples
I've seen), adding the initialization required to get the compiler to stop
complaining can actually result in what is effectively an uninitialized
value bug, because the otherwise-unnecessary initialization hides any other
problems with initialization.
It's not a compiler bug. The compiler is working exactly to the
language specification, as it should do.
Now, if you want to complain that the language specification is
"wrong" - the specification is already fairly complicated in terms of
working out precisely when a variable is definitely assigned. I believe
it is much better to make a language slightly "dumber" but simpler to
reason about (i.e. simpler to make sure the compiler is correct,
simpler to make sure the specification doesn't let some oddities
through etc) than to try to make it incredibly smart.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: try...catch and local variables
- From: Peter Duniho
- Re: try...catch and local variables
- References:
- Re: try...catch and local variables
- From: Mythran
- Re: try...catch and local variables
- From: Peter Duniho
- Re: try...catch and local variables
- From: Mythran
- Re: try...catch and local variables
- From: Peter Duniho
- Re: try...catch and local variables
- Prev by Date: Re: ValueType reference in objects
- Next by Date: Re: short res = shortA + shortB result in compiler error. Why?
- Previous by thread: Re: try...catch and local variables
- Next by thread: Re: try...catch and local variables
- Index(es):
Relevant Pages
|