You must have used the debugging function of eclipse. In the debugging process, you cannot avoid using breakpoints. However, you may not know about all types of breakpoints in eclipse. This article illustrates all types of breakpoints and their settings in eclipse, hoping to help you. (2011.11.20)
1. Sample program
Breakpointdemo is a hypothetical application, just to facilitate the use of various breakpoints in eclipse. Shows the code,
Breakpointdemo mainly includes two methods:
[1] setvalue, which is a random integer ranging from 0-9 based on the specified Count value.
[2] printvalue. This method calls setvalue () to assign values and prints the value. However, if the value can be divisible by 3, an illegalargumentexception exception is thrown.
2. Line breakpoint
Line breakpoin is the simplest eclipse breakpoint. If you double-click the left sidebar corresponding to a line of code, you can set a breakpoint for this line. Here, set line breakpoint for the 20th line of code, as shown in,
You can set a condition for line breakpoint. When the program runs to this breakpoint, it will be interrupted only when the Preset conditions are met. Right-click the breakpoint in row 20th and select "breakpoint properties ..."
In the displayed Properties dialog box, select "Conditional" and enter "count % 2 = 0" in the text box ".
This condition indicates that the program will be interrupted only when the Count value is an even number when the program runs to the 20th row. If you are careful, you will find that the breakpoint icon has changed and a question mark is added.
3. watchpoint
Line breakpoint focuses on the "process" of running programs. It is often called single-step debugging. However, sometimes we do not know much about the running process of the program and may not care much about it. We are not sure where to set the breakpoint is appropriate, but may pay more attention to the changes or usage of a key variable. In this case, you can set a special breakpoint -- watchpoint for this variable. In this example, we are most concerned with the value of the member variable value, so we can set a watchpoint for it and double-click the left column corresponding to the code of line 9th.
Use the method mentioned in 2 to view the breakpoint attributes,
By default, the program is interrupted when the variable is accessed or its value is modified. However, in this example, the program needs to be interrupted only when the value is modified. Therefore, uncheck "access.
At this time, we will find that the original watchpoin icon has also changed.
4. Method breakpoint
Like accessing and modifying a variable, we can also focus on the call situation of a program to a method, that is, we can set a method breakpoint. Here, set the method breakpoint for the method setvalue. Similarly, double-click the left sidebar corresponding to the Code in line 11th.
You still need to view the properties of the breakpoint. By default, only "entry" is selected, but "exit" is not selected ".
This indicates that the program will be interrupted when the method is started (the call starts). However, when the method is left (the call ends), the program will not be interrupted. In this example, select "exit" at the same time ".
After clicking OK, you can see that the breakpoint icon has changed.
According to the settings here, when the program runs to 20th rows, it will be interrupted in 12th rows. Although there is no explicit breakpoint, This is the entry of the setvalue () method ). It must be noted that the program will not be interrupted when running to 16th rows, although it looks like the exit (exit) of the setvalue () method ). In fact, the program will be interrupted in line 1. This is the end of the setvalue () call.
5. Exception breakpoint
If we expect the program to be interrupted when a specific exception occurs, we can easily view the status of the program at that time. This goal can be achieved by setting exception breakpoint. In this example, the illegalargumentexception exception is thrown in Row 3. We expect the program to be interrupted when the program runs here. However, we do not directly set line breakpoint for this line of code, but set exception for illegalargumentexception.
Breakpoint. The method for setting exception breakpoint is different from that for other types of breakpoints. It cannot be set directly in the code editor by double-clicking the left sidebar. Click the Tianji icon in the upper-right corner of the breakpoints view,
The following dialog box is displayed,
Select illegalargumentexception and click OK. An exception breakpoint is set.
When the value is a multiple of 3, the program will be interrupted in line 23rd, then we can use the debugger to see whether the value is equal to 0, 3 or 6.
6. class load breakpoint
There is also a breakpoint that you may not normally use-class load breakpoint, that is, when a class is loaded, the program can be interrupted through this breakpoint.
Summary
The above eclipse breakpoint has certainly been intentionally or unintentionally used in our real work, but we may not be very familiar with it. Using various breakpoints of eclipse can help us analyze programs and locate problems.
From: http://www.blogjava.net/jiangshachina/archive/2011/11/20/364367.html