Unlock IntelliJ IDEA’s Advanced Debugging: Log, Field & Exception Breakpoints
Learn how to leverage IntelliJ IDEA’s powerful debugging features—including Evaluate and Log at breakpoints, field access/modification watches, exception breakpoints, and method breakpoints—to inspect variables, trace execution, and streamline both everyday debugging and deep source code analysis without cluttering your code with temporary prints.
Preface
The previous article introduced IntelliJ IDEA’s Stream Trace as a tasty appetizer of advanced debugging tricks. Building on that, this guide presents several essential IntelliJ IDEA debugging techniques that can dramatically speed up daily work and source‑code reading.
Add Log at Breakpoints
Many developers sprinkle print statements while debugging, then forget to remove them before committing, which adds noise to the log tree and requires extra cleanup. IntelliJ IDEA’s Evaluate and Log at Breakpoints feature solves this problem.
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;
}To view the value of i at line 15 without adding explicit logs, place a breakpoint and press Shift + Left‑Click. The dialog that appears lets you enable Evaluate and log and specify an expression such as "interested" + i. Running the program in Debug mode prints only the evaluated logs:
interested 7
interested 5
interested 1
interested 2
interested 0
Found 2 interested valuesFor more detailed output, you can also enable the "Breakpoint hit" message, which adds a line indicating where the breakpoint was triggered.
Field Breakpoints
When tracing source code, you may wonder where a particular field is modified. IntelliJ IDEA allows you to set a breakpoint on a field so that execution stops whenever the field is accessed or changed.
Click the left mouse button on the field declaration to add a breakpoint (an eye icon appears).
Right‑click the eye icon.
In the dialog, check Field access and Field modification. You can also add a condition to filter when the breakpoint triggers.
Exception Breakpoints
To stop execution right before an exception is thrown, use IntelliJ IDEA’s Exception Breakpoints. After selecting the desired exception type (e.g., NumberFormatException) in the breakpoint settings, the debugger will pause at the throw point, allowing you to inspect variable states.
Method Breakpoints
You can also place breakpoints on interface methods (e.g., in Spring) to see which implementation is invoked at runtime. Use cmd+F8 (macOS) or ctrl+F8 (Windows/Linux) to add the breakpoint, then optionally define a condition.
Click the left mouse button on the method name to add a breakpoint (diamond shape).
Right‑click the breakpoint and enable the desired options, such as a custom Condition.
Summary
With these four advanced debugging techniques—log evaluation, field watch, exception breakpoints, and method breakpoints—you can debug more efficiently and explore source code with confidence. Experiment with the various breakpoint types supported by IntelliJ IDEA to find the workflow that best fits your needs.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
