다음 서브 루틴에서 예외가 throw 될 때 StreamReader
이 제대로 닫힙니 까? 아니면 내가 이것을 보장하기 위해 뭔가해야합니까?예외가 발생한 시나리오에서 StreamReader 범위 지정
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
'...'내에서 예외가 발생하면 'StreamReader'및 파일 핸들 등이 닫힙니 까? –
StreamReader/기본 스트림에서 사용하는 모든 리소스를 해제하는 Using 블록을 실행하면 StreamReader에서 자동으로 .Dispose()가 호출됩니다. – JamesMLV
에이스, 고마워. 나는 어쨌든 enclosing function scope를 떠날 때 어째서 그렇게되지 않는지 궁금하다. 그 밖의 것에는 참조가 없습니다. –