17.2. The Basics of Debugging

Debugging is the process of finding and fixing bugs in your code. Although that may sound easy, it often isn't. Some bugs are very obvious and easy to spot and thus easy to fix. Others are much harder to find and require knowledge about the execution environment of your program. The debugging tools that ship with Visual Web Developer help you understand this execution environment by giving you direct access to the inner workings of your program or web page.

Debugging with VWD is like snapping your fingers to stop the time. When you do that, everything halts, except for you, so you can walk around in your code, investigate variables, look into objects, try out methods, and even execute new code. To tell VWD where to halt, you need to set one or more breakpoints in your code. When the code under the breakpoint is about to be executed, VWD stops the execution of the application (usually a web page, a user control or code in the App_Code folder) and then puts focus back on VWD so you can diagnose the code and its environment.

You set a breakpoint by pressing F9 on the line of code where you want execution to halt. Instead of the F9 shortcut key, you can also click the margin of the code, where the big dot appears in Figure 17-6, or you can choose Debug Toggle Breakpoint from the main menu. Pressing F9, clicking the same spot in the margin, or choosing ...

Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.