VB.NET: question about "using" block
Posted
by Craig Johnston
on Stack Overflow
See other posts from Stack Overflow
or by Craig Johnston
Published on 2010-06-15T08:17:32Z
Indexed on
2010/06/15
8:22 UTC
Read the original article
Hit count: 295
Consider the code:
On Error Goto ErrorHandler
Using sr As StreamReader = New StreamReader(OpenFile)
str = sr.ReadToEnd
sr.Close()
End Using
Exit Sub
ErrorHandler:
If there is an error inside the Using block how do you clean up the sr object?
The sr object is not in scope in ErrHandler so sr.Close() cannot be called. Does the Using block cleanup any resources automatically even if there is an error?
© Stack Overflow or respective owner