Thursday, September 19, 2024

How to Use Breakpoints

This article is an excerpt from the book: Murach’s ASP.NET 2.0 Web Programming with C# 2005.

Figure 4-9 shows how to use breakpoints in an ASP.NET application. Note that you can set a breakpoint before you run an application or as an application is executing. Remember, though, that an application ends after it generates a page. So if you switch from the browser to Visual Studio to set a breakpoint, the breakpoint won’t be taken until the next time the page is executed. If you want a breakpoint to be taken the first time a page is executed, then, you’ll need to set the breakpoint before you run the application.

After you set a breakpoint and run the application, the application enters break mode before it executes the statement that contains the breakpoint. In this illustration, for example, the application will enter break mode before it executes the statement that caused the exception in figure 4-8 to occur. Then, you can use the debugging features described in the topics that follow to debug the application.

In some cases, you may want to set more than one breakpoint. You can do that either before you begin the execution of the application or while the application is in break mode. Then, when you run the application, it will stop at the first breakpoint. And when you continue execution, the application will execute up to the next breakpoint.

Once you set a breakpoint, it remains active until you remove it. In fact, it remains active even after you close the project. If you want to remove a breakpoint, you can use one of the techniques presented in this figure. You can also work with breakpoints from the Breakpoints window. To disable a breakpoint, for example, you can remove the check mark in front of the breakpoint. Then, the breakpoint isn’t taken until you enable it again.

You can also move to a breakpoint in the Code Editor window by selecting the breakpoint in the Breakpoints window and then clicking on the Go To Source Code button at the top of this window, or by right-clicking the breakpoint in the Breakpoints window and choosing Go To Source Code from the shortcut menu.

The Order page with a breakpoint

How to set and clear breakpoints

To set a breakpoint, click in the margin indicator bar to the left of the statement where you want the break to occur. The statement will be highlighted and a breakpoint indicator (a large dot) will appear in the margin. You can set a breakpoint before you run an application or while you’re debugging the application.

To remove a breakpoint, click the breakpoint indicator. To remove all breakpoints at once, use the Debug>Clear All Breakpoints command.

To temporarily disable breakpoints, use the Debug>Disable All Breakpoints command. You can later enable the breakpoints by using Debug>Enable All Breakpoints.

Description

When ASP.NET encounters a breakpoint, it enters break mode before it executes the statement on which the breakpoint is set. From break mode, you can use the debugger to determine the cause of an error.

The current breakpoints are listed in the Breakpoints window (Debug>Windows> Breakpoints). You can use the toolbar at the top of this window to work with the breakpoints, and you can use the check box next to a breakpoint to enable or disable the breakpoint.

You can’t set breakpoints on blank lines or comments.

Add to Del.icio.us | Digg | Yahoo! My Web | Furl

Bookmark Murdok:

Joel Murach has been writing and editing for more than 10 years. During that time, he sharpened his programming skills as a contract programmer in San Francisco and his instructional skills as a trainer for HarperCollins Publishing. He always brings a vision to his projects that leads to improved effectiveness for his readers.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

City cape coral.