Error handling is another area in which we often find ourselves taking shortcuts. We will
also look at error handling methods in this chapter, and we'll see how to deliver user-friendly
messages to our users.
Debugging
Debugging is the process of stepping through code to find inconsistencies due to coding
errors when output is not what you expected, or to find the cause of errors at runtime.
Here are some examples of output not displaying what??™s expected:
??? When reading file names from an array, the file you expected does not open. Something
causes your code to find the incorrect array element. How do you determine where that
incorrect value came from?
??? You??™re reading data from a database but there is nothing there, or the data is not the
data you expected. Is your SQL correct? Is the database there?
??? You??™re reading information from a collection but the collection is empty. Why is the
collection empty?
To determine what??™s happening under the covers while our code is running, we need the
ability to see inside the variables as they are populated with data. We need to be able to follow
our code through any looping or branching structures, and we need a way to stop code at a
predetermined point (or points), or based upon whether certain conditions are met.
The Debugger??™s Toolkit
The VBE gives us tools to do all of the above and more. The Debug menu, shown in Figure 7-1,
contains the VBE??™s debugging command. The Debug toolbar (Figure 7-2) contains commonly
used commands from the Debug menu.
Pages:
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239