Advanced IntelliJ IDEA Debugging Techniques: Evaluate and Log, Field, Exception, and Method Breakpoints
This article introduces several advanced IntelliJ IDEA debugging techniques—including Evaluate and Log at breakpoints, field breakpoints, exception breakpoints, and method breakpoints—providing step‑by‑step instructions, code examples, and screenshots to help Java developers debug more efficiently without cluttering source code.
Adding Log at Breakpoints
Many developers use print statements for debugging, which often remain in code and cause extra work during code review. IntelliJ IDEA’s “Evaluate and Log at Breakpoints” feature allows you to log expressions without modifying the source.
public static void main(String[] args) {
ThreadLocalRandom random = ThreadLocalRandom.current();
int count = 0;
for (int i = 0; i < 5; i++) {
if (isInterested(random.nextInt(10))) {
count++;
}
}
System.out.printf("Found %d interested values%n", count);
}
private static boolean isInterested(int i) {
return i % 2 == 0;
}By pressing Shift + left‑click on a line, you can open the “Evaluate and Log” dialog, enter an expression such as "interested" + i , and run the program in Debug mode to see the logged values without adding explicit print statements.
interested 7
interested 5
interested 1
interested 2
interested 0
Found 2 interested valuesEnabling the “Breakpoint hit” message shows the location of each breakpoint, and checking “Stack trace” provides a full call stack.
Field Breakpoints
When reading source code, you may need to know where a field’s value changes. IntelliJ IDEA lets you add a breakpoint on a field and select “Field access” or “Field modification” to pause execution whenever the field is read or written.
Optionally, you can add a condition in the “Condition” box to filter when the breakpoint triggers.
Exception Breakpoints
To stop execution before an exception is thrown, use Exception Breakpoints. Choose the exception type (e.g., NumberFormatException ) and the IDE will pause at the point where the exception is about to be thrown, showing variable values.
Method Breakpoints
You can also set breakpoints on interface methods (e.g., cmd+F8 or ctrl+F8 ) and configure conditions. When debugging, the IDE will jump directly to the concrete implementation that is invoked.
Conclusion
These four debugging techniques—evaluate‑and‑log, field, exception, and method breakpoints—help developers debug Java applications more efficiently, whether working on daily tasks or reading source code.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.