90 likes | 140 Views
Lecture 3 Debugging and Error Handling. Debugging Techniques. Outputting Debugging Information
E N D
Lecture 3 Debugging and Error Handling
Outputting Debugging Information Writing text to the Output window at runtime is easy. You simply replace calls to Console.WriteLine() with the required call to write text where you want it. There are two commands you can use to do this: Debug.WriteLine() Trace.WriteLine() These commands function in almost exactly the same way, with one key difference — the # rst command works in debug builds only; the latter works for release builds as well. In fact, the Debug.WriteLine() command won’t even be compiled into a release build; it just disappears. These require the inclusion of using System.Diagnostics;
Using Tracepoints To demonstrate tracepoints, you can use them to replace the debugging commands in the previous example. The process for adding a tracepoint is as follows: 1. Position the cursor at the line where you want the tracepoint to be inserted. The tracepoint will be processed before this line of code is executed. 2. Right-click the line of code and select Breakpoint ! Insert Tracepoint. 3. Type the string to be output in the Print a Message text box in the When Breakpoint Is Hit dialog box that appears. If you want to output variable values, enclose the variable name in curly braces. 4. Click OK. A red diamond appears to the left of the line of code containing a tracepoint, and the line of code itself is shown in red.
Breakpoints A breakpoint is a marker in your source code that triggers automatic entry into break mode. Breakpoints can be configured to do the following: