1 / 8

Debugging

Debugging. K. R. C. Wijesinghe Trainer Virtusa Corporation. Debugging using Visual Studio .Net IDE. Compile Time Errors (Syntax Errors) E.g. for (int i = 0; i < V.Length; i++ ] { V [ i ] = 0; } Run-time Errors (Exceptions) E.g. for (int i = 0; i <= V.Length; i++)

omar-carr
Download Presentation

Debugging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Debugging K. R. C. Wijesinghe Trainer Virtusa Corporation

  2. Debugging using Visual Studio .Net IDE

  3. Compile Time Errors (Syntax Errors) E.g. for (int i = 0; i < V.Length; i++] { V [ i ] = 0; } Run-time Errors (Exceptions) E.g. for (int i = 0; i <= V.Length; i++) { V [ i ] = 0; } Logical Errors E.g. for (int i = 1; i < V.Length; i++) { V [ i ] = 0; } Types of Errors

  4. These classes are defined in System.Diagnosis namespace. Both classes has the same methods and properties. Methods in Debug class will work only if “DEBUG” macro is defined. (This is defined in Debug builds by default). Methods in Trace class will work only if “TRACE” macro is defined. (This is defined in Visual Studio.NET projects by default). Debug and Trace classes

  5. Asserts are used to ensure that a given condition is true at a given point in the program. Asserts will stop the program execution temporarily, if the condition is false, and provide you with three options. They are “Abort”, ”Retry” and “Ignore”. Abort – Stop the program execution. Retry – Take you to the Debug mode. Ignore – Continue with the program. E.g. Stop execution if Obj is null Trace.Assert (Obj != null); Stop execution and display the message “Out of Range” if n > 100. Trace.Assert (n > 100, “Out of Range”); ASSERTS

  6. Dumping information about intermediate steps of the program to an output device, without stopping the execution. This is very important in locating errors in complex programs. The default output is going to the “Output” window of Visual Studio.NET IDE. It can be send to console, a file or Windows event log. Logging

  7. Trace.WriteLine (“Begin Section 1”); int n = 100; Trace.Indent( ); Trace.WriteLine(“Inside Section 1”); Trace.WriteLine( n ); n += 100; Trace.WriteLineIf (n > 150, “n greater than 150”); Trace.Unindent( ); Trace.WriteLine(“End Section 1”); Output: Begin Section1 Inside Section 1 100 n greater than 150 End Section 1 Logging Example

  8. // Output to Console Trace. Listeners.Add (new TextStreamTraceListener(Console.Out); // Output to a file TextWriterTraceListener TraceFile = new TextWriterTraceListener(@“C:\Temp\Test.log”); Trace.Listeners.Add (TraceFile ); ... TraceFile.Close(); // Output to event log EventLogTraceListener ELog = new EventLogTraceListener("TestLog1"); Trace.Listeners.Add (ELog); Trace.WriteLine( “Test Log Message”); Sending output to Other devices

More Related