Visual Studio Next Generation: Language Enhancements

Structured Exception Handling

Developing enterprise applications requires the construction of reusable, maintainable components. One challenging aspect of the Basic language in past versions of Visual Basic was its support for error handling. In the past, developers had to provide error-handling code in every function and subroutine. Developers have found that a consistent error-handling scheme means a great deal of duplicated code. Error handling using the existing On Error GoTo statement sometimes slows the development and maintenance of large applications. Its very name reflects some of these problems: As the GoTo implies, when an error occurs, control is transferred to a labeled location inside the subroutine. Once the error code runs it must often be diverted via another cleanup location via a standard GoTo, which finally uses yet another GoTo or an Exit out of the procedure. Handling several different errors with various combinations of Resume and Next quickly produces illegible code and it leads to frequent bugs when execution paths aren't completely thought out.

With Try...Catch...Finally, these problems go away, developers can nest their exception handling, and there is a control structure for writing cleanup code that executes in both normal and exception conditions.

Sub SEH()
    Try
       Open "TESTFILE" For Output As #1
       Write #1, CustomerInformation
    Catch
       Kill "TESTFILE"
    Finally
       Close #1
    End try
End Sub

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson