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

Chapter 9 - Structured Error Handling

By , About.com Guide

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
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.