J
Jack Jackson
I want to open a filestream and so some processing. If the open
throws an exception I want to throw a custom exception. If any other
exception occurs during the processing I want that exception to bubble
up.
The code without Using would be:
dim fs As IO.FileStream
try
fs = IO.File.Open(parmFileName, IO.FileMode.Create)
catch
<<Throw custom exception>>
end try
<< Code that writes using fs>>
fs.close()
fs.Dispose()
The only thing I can think of is this, but it seems kludgy to me:
Dim rethrow As Boolean = False
Try
Using fs = IO.File.Open(parmFileName, IO.FileMode.Create)
rethrow = True
<<Processing>>
fs.Close()
End Using
Catch
If rethrow
Throw
End If
<<Throw custom exception>>
End Try
throws an exception I want to throw a custom exception. If any other
exception occurs during the processing I want that exception to bubble
up.
The code without Using would be:
dim fs As IO.FileStream
try
fs = IO.File.Open(parmFileName, IO.FileMode.Create)
catch
<<Throw custom exception>>
end try
<< Code that writes using fs>>
fs.close()
fs.Dispose()
The only thing I can think of is this, but it seems kludgy to me:
Dim rethrow As Boolean = False
Try
Using fs = IO.File.Open(parmFileName, IO.FileMode.Create)
rethrow = True
<<Processing>>
fs.Close()
End Using
Catch
If rethrow
Throw
End If
<<Throw custom exception>>
End Try