AvocadoSoftware.com

Software For Hardcore Developers
Welcome to AvocadoSoftware.com Sign in | Join | Help
in Search

Derick Baileys old blog archives - go to derickbailey.com for new contents

Request for VB.NET Language: variable scope in Try Catch blocks

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.

Published Friday, February 25, 2005 8:13 AM by dredge
Filed Under:
New Comments to this post are disabled

This Blog

Post Calendar

<February 2005>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

Advertisement

News

this is my old blog archives - go to http://derickbailey.com for updates

Syndication

Advertisement

Powered by Community Server, by Telligent Systems