I've run into the same thing with if/else constructs. Initializing the variable with a value seems to resolve it;
int myInt = 0;
>I tried what you sugested, but I got a compile error that stated that myObject had not been initialized I found that very odd because that is what I want to check for in the finally block.
>
>Here is a little console app I wrote to ilustrate:
>
>int myInt;
>try
>{
> myInt = 1;
>}
>finally
>{
> if (myInt != 1)
> {
> myInt = -4;
> }
>}
>Console.WriteLine(myInt.ToString());
>
>
>This gives me the following error:
>
use of unassigned local variable myInt>in line 10 (if (myInt != 1))
>
>Any clue?
>
>Einar
>
>
>
>>2. You get an exception because your variable is out of scoop in the finally block. Declare if before the try:
>>
>>
>>Object myObject;
>>try
>>{
>> myObject = new SomeThing();
>>...
>>}
>>finally
>>{
>> if (myObject !=null)
>> {...}
>>}
>>
>>