Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 21,718 times

Contents

Related Categories

Visual Studio Next Generation: Language Enhancements - Structured Exception Handling

Microsoft

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

Comments

  • Object Oriented feature in VB

    Posted by ghanshyam on 12 Nov 2002

    The Object Oriented feature like Inheritance,Polymorphism,Encapsulation in Visual Basic is really a great achievement.Offcourse making a VB program as Multithreaded and allowing STructured exception h...

  • VB History

    Posted by jamsmith on 01 Aug 2002

    I am not sure if you have your whole VB history down. I learned VB from a Version 2.0 Demo. Also, did you also know there was Visual Basic for DOS?