Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

538 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

You have developed the SkyShark Airlines application. Suppose you compile the application and run it. The application does run; however, it generates error messages or displays dialog boxes that might not be interpretable by end

users. By debugging your application, you can track and eliminate these errors.

Visual Studio .NET provides several options to help you in such situations. In this

chapter, I will discuss the various debugging tools provided by Visual Studio

 

 

Y

.NET to debug these errors. This chapter also discusses the points to be consid-

ered while testing the application.

L

 

F

M

 

Locating Errors in Programs

A

 

One of the most difficult tasks in developing an application is finding errors.

E

 

 

With Visual StudioT.NET it is very simple to trace syntax errors. Visual Studio

.NET warns you about syntax errors at the time of writing the code itself. In addition, these errors are listed when you compile the program in the Output window.

Visual Studio .NET provides you with a number of debugging tools and options to enable you to write error-free programs. You can see these tools and options while debugging a Visual Studio .NET program in the break mode. A program is in break mode when any error halts the execution of your program temporarily. You can also introduce a breakpoint in your application. When your application encounters a breakpoint, it enters the break mode. This mode enables you to examine the status of your application by using other debugging tools provided by Visual Studio .NET.

A program can be forced to enter the break mode by setting a breakpoint. You can set a breakpoint simply by placing the cursor on a line and pressing the F9 key. You can also set a breakpoint as follows: On the Debug menu, click the New Breakpoint option. The New Breakpoint dialog box appears as shown in Figure 23-1.

Team-Fly®

DEBUGGING AND TESTING THE APPLICATION

Chapter 23

 

539

 

 

 

 

 

 

FIGURE 23-1 The New Breakpoint dialog box

You can also enter the break mode from within your code by using the Stop statement.

Visual Studio .NET has four types of breakpoints, as follows:

Function breakpoint. Temporarily puts the program execution on hold when the program execution reaches a specific position within a function.

File breakpoint. Causes the program execution to halt when it reaches a specified position within the specified file.

Address breakpoint. Causes the program to break when execution reaches a specific memory location.

Data breakpoint. Causes the program execution to halt when the value of a variable changes.

The advantage of the break mode is that it enables you to modify the values of variables and properties. Now I will discuss other debugging tools available with Visual Studio .NET.

540 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

Watch Window

The Watch window is useful to monitor values of variables and expressions. You can add variables to the Watch window by entering the variable name in the Name column of the window or by selecting QuickWatch option from the Debug window. The Watch window can be invoked only from the break mode. Figure 23-2 displays the Watch window.

FIGURE 23-2 The Watch window

Locals Window

The Locals window displays variables that are local to the current execution context, such as the current function or module. In order to open the Locals window, you must be in debugging mode. To open the Locals window, on the Debug menu, point to Windows, and then click Locals. Figure 23-3 shows the Locals window.

FIGURE 23-3 The Locals window

Call Stack Window

The Call Stack window lists the functions and procedure calls that are currently loaded in memory in the order in which they were called. You can view this window only in the break mode.The Call Stack window displays the sequence of program execution. The Call Stack window is shown in Figure 23-4.

DEBUGGING AND TESTING THE APPLICATION

Chapter 23

541

 

 

 

 

FIGURE 23-4 The Call Stack window

Autos Window

The Autos window displays the name of all variables in the current and previous statement. You need not specify the name of the variable. The Visual Studio

.NET debugger automatically identifies the variables in the current execution location statement and displays them in the window. Figure 23-5 displays the Autos window.

FIGURE 23-5 The Autos window

Command Window

The Command window is used to evaluate expressions or issue commands when in the debug mode. To open the Command window, perform the following steps:

On the View menu, point to Other Windows.

In the displayed list, click on the Command Window option.

The Command window has two modes, Command and Immediate. Command mode is used to issue Visual Studio .NET commands, while the Immediate mode is used for debugging purposes, evaluating expressions, and printing variable values. For example, ? num, where num represents a variable, will return the value stored in the variable. Figure 23-6 displays the Command window.