Hi!
This:
LOCAL oSR as StreamReader
TRY
oSR := StreamReader(cFile)
do while....
enddo
CATCH ex...
FINALLY
oSR:Close()
END TRY
creates error XS0165 for variable oSR.
My question is, how to handle this.
Is oSR already created before exceptions arise? The I consider it OK to do it like that and the message is wrong.
If oSR is NOT already created before exceptions occur, then must I use a separate TRY around the creation of oSR?
try...catch and XS0165 (Use of unassigned local variable...)
try...catch and XS0165 (Use of unassigned local variable...)
It is possible that the constructor of StreamReader fails and throws in exception, in which case oSR will never be assigned indeed, I think that's the theory behind this. In order to get rid of it, you could just assign the var to NULL before the TRY construct, although this is a bit like cheating
Alternatively, you could use a BEGUN USING instead, which also takes care of the closing/disposing of the object:
Chris
Alternatively, you could use a BEGUN USING instead, which also takes care of the closing/disposing of the object:
Code: Select all
BEGIN USING VAR oSR := StreamReader{"..."}
...
END USING
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
try...catch and XS0165 (Use of unassigned local variable...)
Thanks, Chris!
I found another solution:
TRY
oSR := StreamReader(cFile)
try
do while...
enddo
catch...
finally
oSR:Close()
end try
CATCH...
END TRY (note: no FINALLY here, or at least no oSR:Close in it)
BR Kurt
I found another solution:
TRY
oSR := StreamReader(cFile)
try
do while...
enddo
catch...
finally
oSR:Close()
end try
CATCH...
END TRY (note: no FINALLY here, or at least no oSR:Close in it)
BR Kurt