1. Computing

Structured Error Handling


3 of 9

Microsoft's Point of View
Structured Error Handling

Here's the Microsoft documentation of the Catch statement:

A Catch statement handles an exception that is of the same type as the type declared in the Catch statement, or of a type derived from it. If you supply a Catch statement that does not specify an exception type, it handles any exception derived from the Exception class.

A Catch statement, whether or not it specifies an exception type, can optionally include the When clause. When is followed by an expression that must be convertible to Boolean. The exception is handled only if it is of the right type and the When expression evaluates to True.

It doesn't have to be that hard! This translation isn't as exact, but it might be easier to understand, "A Catch block will handle the error in the As Exception clause unless the clause isn't there. Then the Catch statement will try to handle every exception. If you include a When clause, that has to be True before the code in the Catch block will run."

The illustration shows the simplest possible Try-Catch in action where all of the optional clauses are omitted. As you can see, the statements that might generate an exception are in the Try block. In the illustration, there's only one statement in that block. (Which generates a pretty obvious exception since "George" can't be converted into a Decimal type.)

  1. About.com
  2. Computing
  3. Visual Basic
  4. Learn VB.NET
  5. Trapping Errors Using Structured Error Handling

©2014 About.com. All rights reserved.