In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use Eclipse breakpoints, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
1. Sample program
BreakpointDemo is a fictional application, just to make it easy to explain the use of various breakpoints in Eclipse. The code is shown in the following figure
BreakpointDemo consists of two main methods:
[1] setValue, which assigns the member variable value according to the specified number of times (count), whose values range from 0 to 9 random integers.
[2] printValue, which calls setValue () to assign a value to value and prints out the value of value; however, if value is divisible by 3, an IllegalArgumentException exception is thrown.
2. Line Breakpoint
Line Breakpoin is the simplest Eclipse breakpoint. Just double-click the left column for a line of code and set the upper breakpoint for that line. Here, set the Line Breakpoint on line 20, as shown in the following figure
You can set a condition for Line Breakpoint, so that when the program runs to that breakpoint, it will be interrupted only if the set conditions are met. Right-click the breakpoint on line 20 and select "Breakpoint Properties...".
In the pop-up properties dialog box, check "Conditional" and enter "count% 2 = = 0" in the text box.
This condition indicates that when the program runs to line 20, the program will be interrupted only if the count is even. If you are careful, you will find that the icon of the breakpoint has changed and there is an extra question mark.
3. Watchpoint
Line Breakpoint focuses on the "process" of running a program, and debugging using such breakpoints is often referred to as single-step debugging. But sometimes, we don't know much about the running process of the program, and we may not care much about it. We are not sure where to set a breakpoint, but we may pay more attention to the change or use of a key variable. At this point, you can set a special breakpoint for this variable, Watchpoint. 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 line 9 of the code.
Use the method mentioned in 2 to view the properties of the breakpoint
By default, the program is interrupted when the variable is accessed or its value is modified. In this example, however, you only want the program to be interrupted when the value of value is modified, so uncheck "Access".
At this point, we will find that the original Watchpoin icon has also changed.
4. Method Breakpoint
Just as we focus on accessing and modifying a variable, we can also focus on the program's call to a method, that is, we can set the Method Breakpoint. Here, set the Method Breakpoint for the method setValue. Similarly, double-click the left column corresponding to line 11 of the code.
You still want to view the properties of the breakpoint. By default, only "Entry" is checked, not "Exit".
This means that when you first enter the method (the call starts), the program is interrupted; when you leave the method (the call ends), the program is not interrupted. In this example, you need to check "Exit" as well.
After clicking OK, you can see that the icon of the breakpoint has also changed.
According to the settings here, when the program runs to line 20, it will be interrupted on line 12. Although there is no explicit breakpoint here, this is the Entry of the setValue () method. It is important to note that the program is not interrupted when it runs to line 16, although it looks like the Exit of the setValue () method. In fact, the program will be interrupted at line 17, where the setValue () call ends.
5. Exception Breakpoint
If we expect the program to be interrupted when a particular exception occurs, it is easy to see the state of the program at that time. This can be achieved by setting up Exception Breakpoint. This example deliberately throws an IllegalArgumentException exception on line 23, and we expect the program to be interrupted when it runs here. But instead of setting Line Breakpoint directly for this line of code, we set Exception Breakpoint for IllegalArgumentException. The method of setting Exception Breakpoint is different from other types of breakpoints. It cannot be set directly on the code editor by double-clicking on the left sidebar. Click the icon shaped like Ji in the upper right corner of the Breakpoints view
The dialog box shown below pops up.
Select IllegalArgumentException and click OK, and an Exception Breakpoint is set.
When value is a multiple of 3, the program is interrupted at line 23, so we can use the debugger to see if value is equal to 0mem3 or 6.
6. Class Load Breakpoint
There is another breakpoint that people may not normally use-Class Load Breakpoint, that is, when a class is loaded, you can break the program through this breakpoint.
The above is all the contents of the article "how to use Eclipse breakpoints". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.