|
Start-to-Finish Visual Basic 2005. Learn Visual Basic 2005 as You Design and Develop a Complete Application Authors: Patrick T Published year: 2006 Pages: 86-87/247 |
Chapter 9. Error ProcessingDebugging and error processing are two of the most essential programming activities you will ever perform. There are three absolutes in life: death, taxes, and software bugs . Even in a relatively bug-free application, there is every reason to believe that a user will just mess things up royally. As a programmer, your job is to be the guardian of the user's data as managed by the application, and to keep it safe, even from the user 's own negligence (or malfeasance) and also from your own source code. I recently spoke with a developer from a large software company headquartered in Redmond, Washington; you might know the company. This developer told me that in any given application developed by this company, more than 50 percent of the code is dedicated to dealing with errors, bad data, system exceptions, and failures. Certainly, all this additional code slows down each application and adds a lot of overhead to what is already called "bloatware." But in an age of hackers and data entry mistakes, such error management is an absolute must. Testing although not a topic covered in this bookgoes hand-in-hand with error management. Often, the report of an error will lead to a bout of testing, but it should really be the other way around: Testing should lead to the discovery of errors. When I first started work on this chapter, the daily news was reporting that NASA's Mars Global Surveyor , in orbit around the red planet, had captured images of the Beagle 2 , a land-based research craft that crashed into the Martian surface in 2003. An assessment of the Beagle 2 's failure pinpointed many areas of concern, with a major issue being inadequate testing:
Look at all those big words. Boy, the Europeans sure have a way with language. Perhaps a direct word-for-word translation into American English will make it clear what the commission was trying to convey :
|
The Nature of Errors in Visual BasicThere are three major categories of errors that you will deal with in your Visual Basic applications.
Logic errors are too personal and too varied to directly address in this book. Many logic errors can be forced out of your code by adding sufficient checks for invalid data, and by adequately testing your application under a variety of conditions and circumstances. You won't have that much difficulty dealing with compile-time errors. A general understanding of Visual Basic and .NET programming concepts, and a regular use of the tools included with Visual Studio 2005, will help you quickly locate and eliminate them. The bigger issue is: What do you do with run-time errors? Even if you check all possible data and external resource conditions, it's impossible to prevent all run-time errors. You never know when a network connection will suddenly go down, or the user will trip over the printer cable, or a scratch on a DVD will generate data corruption. Any time you deal with resources that exist outside of your source code, you are taking a chance that run-time errors will occur. Figure 9-2 showed you what Visual Basic does when it encounters a run-time error: It displays to the user a generic error dialog, and offers a chance to ignore the error (possible corruption of any unsaved data) or exit the program immediately (complete loss of any unsaved data). Although both of these user actions leave much to the imagination , they don't instill consumer confidence in your coding skills. Trust me on this: The user will blame you for any errors generated by your application, even if the true problem was far removed from your code. Fortunately, Visual Basic includes three tools to help you deal completely with run-time errors, if and when they occur. These three Visual Basic featuresunstructured error handling, structured error handling, and unhandled error handlingcan all be used in any Visual Basic application to protect the user's dataand the userfrom unwanted errors. |
|
Start-to-Finish Visual Basic 2005. Learn Visual Basic 2005 as You Design and Develop a Complete Application Authors: Patrick T Published year: 2006 Pages: 86-87/247 |