10 tips for debugging Java in eclipse

Source: Internet
Author: User

1. Conditional breakpoint

Imagine how to add a breakpoint. Generally, double-click the left side of the row number. In the debug view, the breakpoint view lists all breakpoints, but we can add a Boolean condition to determine whether the breakpoint is skipped. If the condition is true, the program stops at the breakpoint. Otherwise, the breakpoint is skipped and the program continues to run.

 

2. Exception breakpoint

There is one in the breakpoint view that looks like J! You can use it to add an exception-based breakpoint. For example, if we want the program to suspend when nullpointerexception is thrown, we can:

 

3. Observation points

I like this feature very much. It allows the program to pause and debug when a selected property is accessed or changed. The simplest way is to declare the member variable in the class by double-clicking on the left of the statement line number to add an observation point.

 

4. View Variables

Run Ctrl + Shift + D or Ctrl + Shift + I on the selected variable to view the variable value. In addition, you can add monitoring in the expressions view.

 

5. Change the variable value

We can change the value of the variable in debug. You can perform operations as shown in variables view.

 

6. Stop running/debug settings in the main method. We can enable this feature as shown in. The program stops at the first line of the main method.

7. You can easily add environment variables in the edit conriguration dialog box.

8. The drop to frame function is very cool. It is my second favorite feature. The drop to frame function can be re-executed at the beginning of the current method, and the values of all context variables return to that time. Not necessarily the current method. You can click any frame in the current call stack to jump there (except the first frame ). The main purpose is to quickly restore the state of all variables to the beginning of the method and re-execute it, that is, you can perform multiple debugging in the context you are concerned about over and over again (combined with other functions such as variable value change) without re-debugging. Of course, the side effects of the original execution process are irreversible (for example, you have inserted a record into the database ).

9. step filtering: When we press F5 during debugging, it will enter the internal method, but this has a disadvantage that sometimes it may enter some internal libraries (such as JDK ), it may not be what we want. We can add a filter in preferences to exclude the specified package.


10. Enter, skip, and return

In fact, this technique is the most basic knowledge of debug.
  • F5-Step into: Move to next, if the current row is a method call, it will enter the first line of this method. (This can be ruled out through Article 9)
  • F6-Step over: Move to the next row. If the current row has a method call, this method will be returned after execution, and then to the next row.
  • F7-Step return: continues to execute the current method, and when the current method is executed, the control will go to the row that the current method is called.
  • F8-Move to the next breakpoint.

Address: http://www.oschina.net/question/82993_69439

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.