Exception Handling Changes in Visual Basic

 

Visual Basic 6.0

In Visual Basic 6.0, you use unstructured exception handling to deal with errors in your code. Placing the On Error statement at the beginning of a block of code handles any errors that occur within that block. Unstructured exception handling also employs the Error and Resume statements.

Visual Basic .NET

In Visual Basic .NET, structured exception handling code detects and responds to errors during execution by combining a control structure with exceptions, protected blocks of code, and filters. Structured exception handling is done through a Try statement, which is made up of three kinds of blocks: Try, Catch, and Finally. A Try block is a statement block that contains the statement to be executed. A Catch block is a statement block that handles an exception. A Finally block contains statements to be run when the Try statement is exited, regardless of whether an exception has occurred. The Throw statement, used in conjunction with a Catch block, raises an exception that is represented by an instance of a type derived from the System.Exception class.