Detailed Eclipse breakpoints

Source: Internet
Author: User

Http://www.blogjava.net/jiangshachina/archive/2011/11/20/364367.html

detailed Eclipse Breakpoints

Everyone must have used the debugging capabilities of Eclipse, and in the process of debugging it is not natural to avoid using breakpoints (breakpoint), but I do not know whether the various breakpoints in eclipse are known. This article provides an illustrated overview of all types of breakpoints in Eclipse and their settings, and we hope to help. (2011.11.20)

1. Sample Programs
Breakpointdemo is a figment application, just for the purpose of explaining the use of various breakpoints in eclipse. As shown in the Code,

Breakpointdemo consists of two main methods:
[1]setvalue, the method assigns a value of member variable value to a random integer with a range of 0-9, based on the specified number of times (count).
[2]printvalue, the method calls SetValue () to assign value and prints out the value of value, but if value is divisible by 3, a IllegalArgumentException exception is thrown.

2. Line Breakpoint
Line Breakpoin is the simplest eclipse breakpoint, as long as you double-click the left column of a line of code to set a breakpoint on that row. Here, the line breakpoint is set on the 20th row of code, as shown in

You can set a condition for line breakpoint, and when the program runs to that breakpoint, it will be interrupted only if it satisfies the set criteria. Right-click the breakpoint on line 20th and select "Breakpoint Properties ..."

In the pop-up Properties dialog box, tick "Conditional" and enter "count% 2 = = 0" In the text box.

This condition indicates that the program will be interrupted only if Count is an even number when the program is running to the 20th row. Carefully, you will find that the breakpoint icon has changed, a question mark is more.


3. Watchpoint
Line breakpoint is concerned with the "process" of running a program, which is often referred to as one-step debugging using this breakpoint. Sometimes, however, we are not familiar with the process of running the program, and may not be too concerned, not sure where to set the breakpoint is appropriate, but may be more concerned about a key variable changes or use. At this point, you can set a special breakpoint--watchpoint for the variable. In this example, we are most concerned about the value of the member variable values, then you can set a watchpoint for it, double-click the 9th Line of code corresponding to the left column is OK.

Use the method mentioned in 2 to view the properties of the breakpoint,

By default, when the variable is accessed or its value is modified, the program will be interrupted. However, in this example, you only want the program to be interrupted when you modify the value, so uncheck the "Access".

At this point, we will find that the original Watchpoin icon has also changed.


4. Method Breakpoint
As with attention to the access and modification of a variable, we can also focus on the procedure's invocation of a method, that is, you can set method breakpoint. Here, you set the method breakpoint for methods SetValue. Similarly, double-click on the left column of the 11th line of code.

You still want to view the properties of the breakpoint. By default, only "Entry" is checked, and "Exit" is not selected.

This means that the program is interrupted when the method is first entered (the invocation begins), and the program is not interrupted when it leaves the method (the call ends). In this example, you need to tick "Exit" at the same time.

After clicking OK, you can see that the icon for the breakpoint has also changed.

Depending on the settings here, when the program runs to line 20th, it will be interrupted on line 12th, although there are no explicit breakpoints, but this is the SetValue () method's entry (Entry). It must be noted that the program will not be interrupted when it runs to line 16th, although it looks like the exit (exit) of the SetValue () method. In fact, the program will be interrupted on line 17th, where the SetValue () call ends.

5. Exception Breakpoint
If we expect a particular exception to occur, the program can be interrupted to make it easier to see the state of the program at that time. This can be achieved by setting the exception breakpoint. This example intentionally throws a IllegalArgumentException exception on line 23rd, and we expect the program to be interrupted when it is run here. But instead of setting line breakpoint directly for this row of code, we set the exception breakpoint for IllegalArgumentException. The method of setting exception breakpoint is different from other types of breakpoints, and it cannot be set directly on the Code Editor by double-clicking the left column. Click on the icon in the upper-right corner of the breakpoints view like Ji

A dialog box like the following will pop up,

Select IllegalArgumentException in it, and click OK, then a exception breakpoint is set up.

When value is a multiple of 3, the program is interrupted on line 23rd, so we can use the debugger to see if value is equal to 0, 3, or 6.


6. Class Load Breakpoint
There is also a breakpoint--class load breakpoint that you might not normally use, that is, when a class is loaded, the breakpoint can break the program.


Summary
The Eclipse breakpoint above, we certainly have in the real work has intentionally or unintentionally used several of them, but do not necessarily know very well. Using the various breakpoints of eclipse can be a good way to help us analyze the program and locate the problem.

Detailed Eclipse breakpoints

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.