Req13: Catches in Using blocks

[This post is part of a series, "wish-list for future versions of VB"]

 

IDEA: Allow Catch statements in Using blocks. A Using block is just a Try/Finally block that calls "Dispose" in its destructor. It'd be handy if you could stick "Catch" statements inside the Using block as well. In other words, this code

        Using x As New C

            ....

        Catch ex As System.IO.FileFormatException

....

End Using

would be shorthand for this:

        Dim x As New C

        Try

....

Catch ex As System.IO.FileFormatException

            ....

        Finally

            If x IsNot Nothing Then

                x.Dispose()

            End If

        End Try

 

Provisional evaluation from VB team: it's a decent idea, one worth considering against the other desirable features. What do you think? Does it provide enough benefit to be worth adding to the language?