Share via


Troubleshooting Exception Handling (Visual Basic)

This topic describes problems commonly encountered when working with exceptions and how to address them.

Visual Basic supports structured exception handling, which you can use to create and maintain programs with robust, comprehensive error handlers. Structured exception handling is code designed to detect and respond to errors during execution by combining a control structure (similar to Select Case or While) with exceptions, protected blocks of code, and filters.

Inner Exceptions

In cases where an exception is thrown as a direct result of a previous exception, the InnerException property describes the original error. This information helps you to handle the error more efficiently. If there is no original error, the value of InnerException will be a null reference or Nothing in Visual Basic. This property is read-only. For more information, see How to: Check an Exception's Inner Exception (Visual Basic).

Try…Catch Statements

Your code may not correctly catch exceptions if you order your Catch blocks incorrectly. Your Catch statements should move from most specific to least specific. A Catch block by itself will catch all exceptions derived from Exception, and therefore should always be placed as the last block before Finally.

See Also

Tasks

Walkthrough: Structured Exception Handling (Visual Basic)

Concepts

Choosing When to Use Structured and Unstructured Exception Handling (Visual Basic)

Other Resources

Exception Handling Tasks (Visual Basic)