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

Chapter 9 - Structured Error Handling

By Dan Mabbutt, About.com

4 of 10

The Difference in Code

Here's the difference in code. At the bottom of page 236, the book suggests this way to test for a specific exception type:

~~~~~~~~~~~~~~~~~~~~~~~~~
Try
  PictureBox1.Image = _
    System.Drawing.Bitmap.FromFile("a:\fileopen.bmp")
Catch When Err.Number = 53
... the rest of the code is the same
~~~~~~~~~~~~~~~~~~~~~~~~~

Here's the same thing coded the Microsoft way:

~~~~~~~~~~~~~~~~~~~~~~~~~
Try
  PictureBox1.Image = _
    System.Drawing.Bitmap.FromFile("a:\fileopen.bmp")
Catch ex As FileNotFoundException
     ... the rest of the code is the same
~~~~~~~~~~~~~~~~~~~~~~~~~

4 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.