C#
  Home arrow C# arrow Page 5 - Testing and Debugging a Windows Forms Appl...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Testing and Debugging a Windows Forms Application
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2006-07-06

    Table of Contents:
  • Testing and Debugging a Windows Forms Application
  • How to get help information
  • How to run a project
  • How to test a project
  • How to debug runtime errors
  • Perspective

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Testing and Debugging a Windows Forms Application - How to debug runtime errors


    (Page 5 of 6 )


     
    When a runtime error occurs, Visual Studio enters break mode. In that mode, Visual Studio displays the Code Editor and highlights the statement that couldn’t be executed, displays the Debug toolbar, and displays an Exception Assistant dialog box like the one shown in figure 3-15. This is designed to help you find the cause of the exception (the bug), and to debug the application by preventing the exception from occurring again or by handling the exception. For example, you can often handle an exception by displaying an appropriate message to the user. This message may give the user one or more options for dealing with the exception.

    Often, you can figure out what caused the problem just by knowing what statement couldn’t be executed, by reading the message displayed by the Exception Assistant, or by reading the troubleshooting tips displayed by the Exception Assistant. But sometimes, it helps to find out what the current values in some of the variables or properties in the program are. To do that, you can place the mouse pointer over a variable or property in the code so a data tip is displayed. This tip displays the current value of the variable or property.

    For example, if the current value of the Text property of the txtSubtotal control is “ABC”, the data tip will clearly show that the Text property does not contain numeric data. However, the variable named subtotal requires numeric data. As a result, you know that the highlighted statement can’t be executed because the user didn’t enter numeric data in the Subtotal text box.

    Once you find the cause of a bug, you can correct it. But first, you must exit from break mode. To do that, you can click the Stop Debugging button in the Debug toolbar. Then, you can correct the problem in the Code Editor and test the application again.

    For now, don’t worry if you don’t know how to correct the problem in this example. Instead, you can assume that the user will enter valid data. In chapter 7, though, you’ll learn how to catch exceptions and validate all user entries for an application because that’s what a professional application has to do.

    How a project looks in break mode


    Figure 3-15.  How to debug runtime errors

    Description

    1. When an application encounters a runtime error, you need to fix the error. This is commonly referred to as debugging, and the error is commonly referred to as a bug.
    2. When an application encounters a runtime error, it enters break mode. In break mode, the Debug toolbar is displayed along with other windows that provide debugging features.
    3. When an application displays the Exception Assistant window, you can read a description of the error. This should give you an idea of what the error might be. You can also click on the links in the Troubleshooting Tips list to display more information in a Help window. You’ll learn more about debugging and the Exception Assistant window in chapter 11.
    4. To display a data tip for a property or variable, move the mouse pointer over it in the C# code. Then, its value is displayed in the data tip.
    5. To exit break mode and end the application, click the Stop Debugging button in the Debug toolbar or press Shift+F5. Then, you can attempt to fix the error, and you can run the application again when you’re done fixing the error.

    More C# Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach's C# 2005," published by Murach. We...
     

    Buy this book now. This article is excerpted from chapter three of the book Murach's C# 2005, written by Joel Murach (Murach, 2005; ISBN: 9781890774370). Check it out today at your favorite bookstore. Buy this book now.

    C# ARTICLES

    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...
    - Color Transformation in C# GDI+ Programming
    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway