Section C.5. Other Features


C.5. Other Features

Visual Studio 2005 provides many new debugging features, that simplify the testing and debugging process. We discuss some of these features in this section.

C.5.1. Edit and Continue

The Edit and Continue feature allows you to make modifications or changes to your code in debug mode, then continue executing the program without having to recompile your code.

1.

Setting a breakpoint. Set a breakpoint at line 11 in your example (Fig. C.22).



Figure C.22. Setting a breakpoint at line 11.


2.

Starting the debugger. Select Debug > Start Debugging. When execution begins, the account1 balance is displayed. The debugger enters break mode when it reaches the breakpoint at line 11.

3.

Changing the input prompt text. Suppose you wish to modify the input prompt text to provide the user with a range of values for variable withdrawalAmount. Rather than stopping the debugging process, add the text "(from 1-49):" to the end of "Enter withdrawal amount for account1" at line 11 in the code view window. Select Debug > Continue. The application prompts you for input using the updated text (Fig. C.23).

Figure C.23. Application prompt displaying the updated text.


In this example, we wanted to make a change in the text for our input prompt before line 11 executes. However, if you want to make a change to a line that already executed, you must select a prior statement in your code from which to continue execution.

1.

Setting a breakpoint. Set a breakpoint at line 14 (Fig. C.24).

Figure C.24. Setting a breakpoint at line 14.


2.

Starting the debugger. Delete the "(from 1-49)" text you just added in the previous steps. Select Debug > Start Debugging. When execution begins, the prompt Enter withdrawal amount for account1: appears. Enter the value 22 at the prompt (Fig. C.25). The debugger enters break mode at line 14 (Fig. C.25).

Figure C.25. Stopping execution at the breakpoint in line 14.


3.

Changing the input prompt text. Let's say that you once again wish to modify the input prompt text to provide the user with a range of values for variable withdrawalAmount. Add the text " (from 1-49):" to the end of "Enter withdrawal amount for account1" in line 11 inside the code view window.

4.

Setting the next statement. For the program to update the input prompt text correctly, you must set the execution point to a previous line of code. Right click in line 11 and select Set Next Statement from the menu that appears (Fig. C.26).

Figure C.26. Setting the next statement to execute.


5.

Select Debug > Continue. The application prompts you again for input using the updated text (Fig. C.27).

Figure C.27. Program execution continues with updated prompt text.


6.

Stopping the debugger. Select Debug > Stop Debugging.

Certain types of change are not allowed with the Edit and Continue feature once the program begins execution. These include changing class names, adding or removing method parameters, adding public fields to a class and adding or removing methods. If a particular change that you make to your program is not allowed during the debugging process, Visual Studio displays a dialog box as shown in Fig. C.28.

Figure C.28. Dialog box stating that certain program edits are not allowed during program execution.


C.5.2. Exception Assistant

Another new feature in Visual Studio 2005 is the Exception Assistant. You can run a program by selecting either Debug > Start Debugging or Debug > Start Without Debugging. If you select the option Debug > Start Debugging and the runtime environment detects uncaught exceptions, the application pauses, and a window called the Exception Assistant appears indicating where the exception occurred, the type of the exception and links to helpful information on handling the exception. We discuss the Exception Assistant in detail in Section 12.4.3.

C.5.3. Just My Code™ Debugging

Throughout this book, we produce increasingly substantial programs that often include a combination of code written by the programmer and code generated by Visual Studio. The IDE-generated code can be difficult for novices (and even experienced programmers) to understandfortunately, you rarely need to look at this code. Visual Studio 2005 provides a new debugging feature called Just My Code™, that allows programmers to test and debug only the portion of the code they have written. When this option is enabled, the debugger will always step over method calls to methods of classes that you did not write.

This feature is not available in Visual Basic 2005 Express. If you have the complete Visual Studio 2005, you can change this setting in the debugger options. Select Tools > Options.... In the Options dialog, select the Debugging category to view the available debugging tools and options. Then click the checkbox that appears next to the Enable Just My Code (Managed only) option (Fig. C.29) to enable or disable this feature.

Figure C.29. Enabling the Just My Code debugging feature in Visual Studio.


C.5.4. Other New Debugger Features

The Visual Studio 2005 debugger offers additional new features, such as visualizers, tracepoints and more, which you can learn about at msdn.microsoft.com/vstudio/express/vb/features/debug/default.aspx.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net