To Microsoft and the VB.NET Development team,
I would like to see a small adjustment made to the variable scoping done inside of a Try ... Catch block. What I would like to see, is a variable declared within a the Try portion of the block, able to be used in the Finally portion of the block, like this:
Private Sub DoSomething()
Try
Dim x As New MyWindowsForm
x.ShowDialog()
Catch ex As Exception
MsgBox(ex.Message)
Finally
x.Dispose()
x = Nothing
End Try
End Sub
In the current version of VB.NET (v2003), I get some nice compiler errors stating that x is not declared, in the Finally block. Since variables are actually declared at the method level, in MSIL, this does not seem to be too large of a request, if you ask me.
I know this request may seem trivial, but I would really like to see it put in place, mostly due to refactoring of old code to place proper try catch blocks. I often have a chunk of code that needs a try catch finally, so that I can properly handle certain exceptions and still dispose of an object (like database connections). It would make life a little more simple and a little more RAD if we could do this, rather than declaring our variables outside of try try catch block.