Exception Handling Changes in Visual Basic
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Exception Handling Changes in Visual Basic

Visual Basic .NET adds support for structured exception handling, and continues support for unstructured exception handling.

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.

See Also

Structured Exception Handling | Unstructured Exception Handling | Try...Catch...Finally Statements (Conceptual) | Try...Catch...Finally Statements (Language Reference) | Throw Statement | On Error Statement | Error Statement | Resume Statement | Exception Class | Programming Element Support Changes Summary

© 2015 Microsoft