I am trying to clear after an exception, and I'm not sure how to handle StreamWriter.
Dim sw As StreamWriter
Try
''
somethingBad1() ''
sw = New StreamWriter(File.Open("c:\tmp.txt", FileMode.Create))
''
somethingBad2() ''
sw.Write("Hello World")
sw.Flush() ''
sw.Close() ''
Catch ex As Exception
sw = Nothing
Finally
sw = Nothing
end try
If somethingBad1 throws an exception, I don't need to do anything with sw; however, if somathignBad2 occurs, it is swalready created, and I need to close it. But how do you know if it was created sw?
source
share