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

Chapter 9 - Structured Error Handling

By Dan Mabbutt, About.com

7 of 10

What Could Go Wrong? - A Few Things That Might Be Confusing

Another potential "gotcha" with Try ... Catch blocks can be illustrated by a modified version of our Divide by Zero example. Suppose you decided to change the program so the values of X, Y, and Z that caused the error would be displayed using the Debug.WriteLine statement. You might try coding it this way:

~~~~~~~~~~~~~~~~~~~~~~~~~
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("exception using X, Y, and Z values" _
   & vbCrLf & vbTab & X & Y & Z)
End Try
~~~~~~~~~~~~~~~~~~~~~~~~~

7 of 10

Explore Visual Basic

More from About.com

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

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

All rights reserved.