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 19 in your example (Fig. C.22).

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

  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 19.
  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 depositAmount. Rather than stopping the debugging process, add the text "(from $1500):" to the end of "Enter deposit amount for account1" at line 19 in the code view window (Fig. C.23). Select Debug > Continue. The application prompts you for input using the updated text (Fig. C.24).

    Figure C.23. Changing the text of the input prompt while the application is in Debug mode.

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

In this example, we wanted to make a change in the text for our input prompt before line 19 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 21 (Fig. C.25).

    Figure C.25. Setting a breakpoint at line 21.

  2. Starting the debugger. Delete the "(from $1-500)" text you just added in the previous steps. Select Debug > Start Debugging. When execution begins, the prompt Enter deposit amount for account1: appears. Enter the value 650 at the prompt (Fig. C.26). The debugger enters break mode at line 21 (Fig. C.26).

    Figure C.26. Stopping execution at the breakpoint in line 21.

  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 depositAmount. Add the text "(from $1500):" to the end of "Enter deposit amount for account1" in line 19 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 16 and select Set Next Statement from the menu that appears (Fig. C.27).

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

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

    Figure C.28. 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.29.

Figure C.29. 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.

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.30) to enable or disable this feature.

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

 

C.5.4. Other New Debugger Features

All of the features discussed thus far in this section are available in all versions of Visual Studio, including Visual C# 2005 Express Edition. The Visual Studio 2005 debugger offers additional new features, such as visualizers, tracepoints and more, which you can learn about at msdn.microsoft.com/vcsharp/2005/overview/debugger.

Preface

Index

    Introduction to Computers, the Internet and Visual C#

    Introduction to the Visual C# 2005 Express Edition IDE

    Introduction to C# Applications

    Introduction to Classes and Objects

    Control Statements: Part 1

    Control Statements: Part 2

    Methods: A Deeper Look

    Arrays

    Classes and Objects: A Deeper Look

    Object-Oriented Programming: Inheritance

    Polymorphism, Interfaces & Operator Overloading

    Exception Handling

    Graphical User Interface Concepts: Part 1

    Graphical User Interface Concepts: Part 2

    Multithreading

    Strings, Characters and Regular Expressions

    Graphics and Multimedia

    Files and Streams

    Extensible Markup Language (XML)

    Database, SQL and ADO.NET

    ASP.NET 2.0, Web Forms and Web Controls

    Web Services

    Networking: Streams-Based Sockets and Datagrams

    Searching and Sorting

    Data Structures

    Generics

    Collections

    Appendix A. Operator Precedence Chart

    Appendix B. Number Systems

    Appendix C. Using the Visual Studio 2005 Debugger

    Appendix D. ASCII Character Set

    Appendix E. Unicode®

    Appendix F. Introduction to XHTML: Part 1

    Appendix G. Introduction to XHTML: Part 2

    Appendix H. HTML/XHTML Special Characters

    Appendix I. HTML/XHTML Colors

    Appendix J. ATM Case Study Code

    Appendix K. UML 2: Additional Diagram Types

    Appendix L. Simple Types

    Index



    Visual C# How to Program
    Visual C# 2005 How to Program (2nd Edition)
    ISBN: 0131525239
    EAN: 2147483647
    Year: 2004
    Pages: 600

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