Enable Conditional Break Point in Eclipse


A condition for a breakpoint can be any logical expression that evaluates to either true or false. The expression is evaluated in the scope of the breakpoint location, meaning you cannot make reference to a class, etc., outside the scope of the breakpoint location when composing your expression.
Consider the following example:

public class Person {   
  String name = "";  
 int age = 0; 
  public Person(String name, int age) {   
   this.name = name;   
   this.age = age;  //breakpoint here 
   } 
 };
If we take the above example, place a breakpoint where indicated and go to the breakpoint properties we can add our condition. In this case we are limited only to the members of the class the breakpoint is contained in and those provided by Object.
For example a valid condition could be:
age == 56 
meaning the breakpoint would only suspend when age was equal to 56.
Conditions can be added to breakpoints by right click on the breakpoint and with the Breakpoint Properties shown below.



Select the Conditional option to enable the ability to provide a custom condition for the breakpoint.
Each breakpoint can have a unique condition that determines when the breakpoint will be hit.

No comments:

Post a Comment