Dela via


Exception Handling for Visual Basic 6.0 Users

Visual Basic 2008 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 2008

In Visual Basic 2008, 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 Exception class.

See Also

Concepts

Structured Exception Handling Overview for Visual Basic

Unstructured Exception Handling Overview

Programming Element Support Changes Summary

Reference

Throw Statement (Visual Basic)

On Error Statement (Visual Basic)

Error Statement

Resume Statement

Exception