Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 10: Special Topics in Data Entry
Last change: February 13 2016 18:47:25.

10.5 Handling Errors

Consider the following program:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim TextFile As IO.StreamWriter MsgBox("Please insert a proper storage device in the USB slot. " _ & "Click the OK button when ready.") TextFile = New IO.StreamWriter("g:\TextFile.txt") TextFile.Write(txtContent.Text) TextFile.Close() End Sub

As you can see, this program saves whatever the user types in a text box named txtContent to a file named TextFile.txt in a removable storage device. Before the Save operation starts, you are careful enough to remind the user to insert the storage device (e.g., flash memory) in the USB slot and then click the OK button when everything is set. The program has no syntax error or logic error, so it appears to be bug free. Does this mean that it will work without any problem? The following discussion provides an answer.

Last change: February 13 2016 18:47:25.
  1. Checking a Pressed Key
  2. Checking Validity of Data Fields
  3. Form Level Validation
  • 10.5 Handling Errors
    1. A User’s Nightmare
    2. The Try…Catch…Finally…End Try Structure
    3. <<PreviousNext>>