5.11. Creating Field, Method, and Exception Breakpoints
Problem
You need to stop execution when a field or method is about to be accessed, or when a certain exception occurs.
Solution
Set a field, method, or exception breakpoint using the appropriate items in the Run menu.
Discussion
The standard breakpoints we’ve been using are called
line breakpoints
; besides line breakpoints, the
JDT supports three other types of breakpoints: field, method, and
exception breakpoints.
Field breakpoints
Field breakpoints
, also
called
watchpoints
,
suspend
execution when your code is going to access and/or modify the value
of a field (watchpoints cannot be set on local variables, only on
fields). This is different from when you set a condition on a
standard breakpoint; this breakpoint happens every time a field is
going to be accessed in any way. Using a watchpoint is often much
easier than trying to catch all the possible points in your code in
which the field you want to watch might be modified.
To set a watchpoint, highlight a field in a Java view and select Run→ Add/Remove Watchpoint. The new watchpoint will appear in the Breakpoints view, and you can configure it by right-clicking it and then clicking Breakpoint Properties, which opens the Java Watchpoint Properties dialog shown in Figure 5-18. Note in particular that you can check two checkboxes here—“Access” and “Modification”—that enable you to indicate whether you want to suspend execution when the field is accessed and/or when it is modified. ...
Get Eclipse Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.