In the following subroutine, will the StreamReader be closed properly when the exception is thrown? Or do I have do something myself to ensure this?
Sub mySub()
Dim sr As StreamReader = File.OpenText("someFilename")
Dim line As String = sr.ReadLine()
While Not (line Is Nothing)
' Some logic here
If someCondition Then
Throw New Exception("someExplanation")
End If
line = sr.ReadLine()
End While
End Sub
You should wrap the StreamReader variable in a using statement.