Visual Basic Concepts
>
Debugging Your Code and Handling Errors
>
No matter how carefully crafted your code, errors can (and probably will) occur. Ideally, Visual Basic procedures wouldn't need error-handling code at all. Unfortunately, sometimes files are mistakenly deleted, disk drives run out of space, or network drives disconnect unexpectedly. Such possibilities can cause run-time errors in your code. To handle these errors, you need to add error-handling code to your procedures.
Sometimes errors can also occur within your code; this type of error is commonly referred to as a bug. Minor bugs — for example, a cursor that doesn't behave as expected — can be frustrating or inconvenient. More severe bugs can cause an application to stop responding to commands, possibly requiring the user to restart the application, losing whatever work hasn't been saved.
The process of locating and fixing bugs in your application is known as debugging. Visual Basic provides several tools to help analyze how your application operates. These debugging tools are particularly useful in locating the source of bugs, but you can also use the tools to experiment with changes to your application or to learn how other applications work.
This chapter shows how to use the debugging tools included in Visual Basic and explains how to handle run-time errors — errors that occur while your code is running and that result from attempts to complete an invalid operation.
Topics
Sample application
.gif) | Errors.vbp Many of the code samples in this chapter are taken from the Errors.vbp sample application. You'll find this application listed in the directory. |