skip navigation
 
 
 
WebInSight
Previous Next

Debugging in TextPad

Unfortunately, no programmer writes mistake-free code 100% of the time, so it is useful to learn how to debug your programs. Here, we will purposely place a bug in our code and then use feedback from the compiler error and TextPad to fix it.

  1. Open HelloWorldBot.cs in TextPad.
  2. Go to line 11, which, before you changed the code, used to say:
    return "Hello World!";
    
    Remove the semicolon from the end of the line.
  3. Press CTRL+1 to compile. You should hear a different sound than when the code properly compiled. The Command Results should also be the front window, which reads:
    HelloWorldBot.cs(11,25): error CS1002: ; expected
    
    Tool completed with exit code 1
    
    This is an error message telling you that the file on line 11, column 25 in HelloWorldBot.cs, a semicolon is expected.
  4. Press CTRL+TAB to switch back to HelloWorldBot.cs from the Command Results window.
  5. Go line 11 (the same line we changed above), and add a semicolon to the end of this line.
  6. Press CTRL+1 to compile HelloWorldBot.cs. You should hear different sound than the error sound, which indicates that compilation was successful. Since there were no error messages, the Command Results window is not brought to the front.

Sometimes compiler error messages can be very cryptic, unlike this straightforward one. Interpreting error messages is a skill gained with experience. Also, the compiler is also not always correct about where the error occurs; the error often occurs on the line before or after the mentioned line. Also, it is not uncommon to have multiple error messages on one compile. In these cases, it is usually best to try and fix the first error message, and then recompile to see if any of the others are corrected by the same change.

Previous Next
 
This work is supported by the following National Science Foundation Grants: CNS-087508, CNS-0549481, IIS-0811884, IIS-0415273
Send comments to Richard Ladner