1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 9 - Structured Error Handling

By Dan Mabbutt, About.com

5 of 10

The Microsoft Way - Here's the Microsoft documentation method

Intellisense

Intellisense

There are two good reasons to code it the Microsoft way.

First, the Microsoft code can be slightly more efficient, especially when several Catch clauses are used, because only the specific clause for the error exception is executed instead of all of them.

But the more important reason is that VB.NET's Intellisense will help you find the exception you need to test for! Help like the illustration shown at the bottom of the page.

Now ... isn't that a lot more convenient than remembering what "53" means?

The information in the Exception object can be useful too. To find out just how useful it is, use your debugging techniques from the previous chapter to find out! Try this code:

~~~~~~~~~~~~~~~~~~~~~~~~~
Try
   ' The traditional Divide By Zero error
   Dim X, Y, Z As Integer
   X = 1 : Y = 0
   Z = X / Y
Catch ex As Exception
   Debug.WriteLine("caught exception" & vbCrLf & vbTab & ex.ToString)
End Try
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Trapping Errors Using Structured Error Handling

©2009 About.com, a part of The New York Times Company.

All rights reserved.