Breakpoints
Breakpoints are source code markers that let you suspend program execution at a specific point and examine its behavior.
Once set, a breakpoint remains in your project until you remove it explicitly (except for temporary line breakpoints). If a file with breakpoints was modified externally, for example, updated through a VCS or changed in an external editor, and the line numbers have changed, breakpoints will be moved accordingly. Note that IntelliJ IDEA must be running when such changes are made, otherwise they will pass unnoticed.
Line breakpoints
Line breakpoints can be set on executable lines of code. Thread execution is suspended before the line with such breakpoint, and IntelliJ IDEA displays the stack frames on that thread's stack.
Set a line breakpoint
-
Place the caret at an executable line of code where you want to set a breakpoint.
If you want to set a breakpoint in the default class constructor, set it on the first line of this class, since the default constructor is mapped to it.
-
Click the left gutter next to that line or press Ctrl+F8.
To set a temporary line breakpoint, press Ctrl+Shift+Alt+F8. It will be removed from your project right after it has been hit.
For lambda expressions, you can set multiple breakpoints within a single line. Click the left gutter and select methods where you want to set a breakpoint from the list:
Remove a line breakpoint
Click the breakpoint icon in the left gutter.
To avoid accidentally removing a breakpoint and losing its parameters, you can choose to remove breakpoints by dragging them to the editor, or by clicking the middle mouse button: in the Settings/Preferences dialog (Ctrl+Alt+S) go to and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then toggle its state (enabled/disabled).
Method breakpoints
Method breakpoints act in response to the program entering or exiting a particular method. They let you follow the program flow at the method level, and check entry and exit conditions.
Set a method breakpoint
Place the caret at the method declaration.
Click the left gutter next to that line.
By default, IntelliJ IDEA sets an emulated method breakpoint, which is a combination of line breakpoints set at first statements of all implementing or overriding methods. Such emulated breakpoints do not impact the debugged application performance, while "true" method breakpoints slow the debugger dramatically due to the JVM design.
Emulated method breakpoints do not work for native methods and classes without the line number information. If this is your case, right-click a method breakpoint and deselect the Emulated option:
Remove a method breakpoint
-
Click the breakpoint icon in the left gutter.
To avoid accidentally removing a breakpoint and losing its parameters, you can choose to remove breakpoints by dragging them to the editor, or by clicking the middle mouse button: in the Settings/Preferences dialog (Ctrl+Alt+S) go to and select Drag to the editor or click with middle mouse button. Simply clicking a breakpoint will then toggle its state (enabled/disabled).
Exception breakpoints
Exception breakpoints are triggered when the specified exception is thrown. They apply globally to the exception condition and do not require a particular source code reference.
Set an exception breakpoint
Press Ctrl+Shift+F8 or select
from the main menu.In the Breakpoints dialog, press Alt+Insert or click , and select Java Exception Breakpoint or JavaScript Exception Breakpoint.
In the Enter Exception Class dialog, specify an exception class from the library or from your project.
Remove an exception breakpoint
Press Ctrl+Shift+F8 or select
from the main menu.In the Breakpoints dialog, select the breakpoint you want to delete under Java Exception Breakpoints and click or press Alt+Delete.
Field watchpoints
Field watchpoints allow you to react to modifications of specific instance variables. For example, if at the end of a complicated process you are ending up with an obviously wrong value on one of your fields, setting a field watchpoint may help determine the origin of the fault.
Set a field watchpoint
During a debugging session, open the Variables view.
Right-click a field and select Add Field Watchpoint from the context menu.
You can also open a class in the editor, locate the field that you want to create a watchpoint for, and Alt+click the left gutter at the field declaration line.
Remove a field watchpoint
Press Ctrl+Shift+F8 or select
from the main menu.In the Breakpoints dialog, select the breakpoint you want to delete under Field Watchpoints and click or press N/A.
Breakpoints properties
Depending on the breakpoint type, you can configure additional properties, such as:
actions to be performed when hitting a breakpoint
a suspend policy that defines whether the application must be suspended when a breakpoint is hit
dependencies on other breakpoints
conditions that define when a breakpoint must be hit
To edit breakpoint properties press Ctrl+Shift+F8, or right-click a breakpoint in the editor gutter.
Option | Description | Breakpoint type |
---|---|---|
Enabled | Clear to temporarily disable a breakpoint without removing it from the project. Disabled breakpoints will be skipped during the debugging process. | Line |
Suspend | Select to pause the program execution when a breakpoint is hit. Suspending an application is useful if you need to obtain logging information or calculate an expression at a certain point without interrupting the program. If you need to create a master breakpoint that will trigger dependent breakpoints when hit, choose not to suspend the program at that breakpoint. Choose the suspend policy:
| Line |
Condition | Select to specify a condition for hitting a breakpoint. A condition is a Java Boolean expression including a method returning This expression must be valid at the line where the breakpoint is set, and it is evaluated each time the breakpoint is hit. If the evaluation result is You can enter multi-line expressions, for example:
if (myvar == expectedVariable) {
System.out.println (myvar);
anotherVariable = true;
}
return true;
| Line |
Log | Select if you want to log the following events to console:
| Line |
Evaluate and log | Select to evaluate an expression when the breakpoint is hit, and show the result in the console output. | Line |
Remove once hit | Select to remove the breakpoint from your project right after it has been hit. | Line |
Disable until breakpoint is hit | Select the breakpoint that will trigger the current breakpoint. Until that breakpoint is hit, the current breakpoint will be disabled. You can also select if you wish to disable it again or leave it enabled once it has been hit. | Line |
Catch class filters | Select to filter out classes where exceptions will be caught. Either type in the filters, or click and configure filters in the Class Filters dialog. You can specify class names or class patterns (strings with the * wildcard). If a filter is specified through a class name, it points at the class itself and all its subclasses. A filter specified through a class pattern points at classes whose fully qualified names match this pattern. Syntax:
For example, | Exception |
Instance filters | Select to limit breakpoint hits with particular object instances. Enter instance IDs separated by spaces, or click and add them in the Instance Filters dialog. | Line |
Class filters | Select to filter classes where the breakpoint must be hit. Either type in the filters, or click and configure filters in the Class Filters dialog. You can specify class names or class patterns (strings with the * wildcard). If a filter is specified through a class name, it points at the class itself and all its subclasses. A filter specified through a class pattern points at classes whose fully qualified names match this pattern. Syntax:
For example, | Line |
Pass count | Select if you need a breakpoint to be triggered only after it has been hit a certain number of times. This is useful for debugging loops or methods called several times. | Line |
Caller filters | Select if you need to stop at a breakpoint only when it is called (or NOT called) from a certain method. Either type in the caller methods, or click and configure filters in the Caller Filters dialog. You can specify method names or method patterns (strings with the * wildcard). Syntax:
| Line |
Watch | ||
Field access | Select to trigger the breakpoint each time the field is accessed. | Field watchpoint |
Field modification | Select to trigger the breakpoint only when the field is modified. | Field watchpoint |
Emulated | This option is set by default when you create a method breakpoint. Instead of using a slow method breakpoint, IntelliJ IDEA sets a combination of line breakpoints at first statements of all implementing or overriding methods that emulate a method breakpoint. We only recommend to deselect this option if you are debugging a remote code (as emulated breakpoints can be very slow to set), or if you need to set a breakpoint at methods without the line number information. | Method |
Method entry | Select to trigger the breakpoint each time the method is entered. | Method |
Method exit | Select to trigger the breakpoint each time the method is exited. | Method |
Notifications | ||
Caught exception | Select to be notified when you've hit a breakpoint on a caught exception. | Exception |
Uncaught exception | Select to be notified when you've hit a breakpoint on an uncaught exception. | Exception |
Productivity tips
- Quick access to most common settings
-
Right-click a breakpoint in the editor gutter to quickly disable or suspend it, or set a condition.
- Breakpoints intentions
-
You can get access to the most common breakpoint actions and filters through intention actions (Alt+Enter).
When a breakpoint is hit, more intention actions are available.
- Group breakpoints
-
You can organize breakpoints into groups, for example, if you need to mark out breakpoints for a specific problem.
In the Breakpoints dialog (Ctrl+Shift+F8), select a breakpoint you want to place in a group and choose from the context menu.
- Move breakpoints
-
To move a line breakpoint, drag it to the target line.
- Copy breakpoints
-
To copy a breakpoint, press Ctrl and drag it to the target line.
- Disable breakpoints
-
To temporarily disable a breakpoint without removing it from the project, hold down the Alt key and click the breakpoint icon in gutter.
- Quick search
-
If you have many breakpoints in your project, you can add short descriptions to them to search for them easily: right-click a breakpoint in the Breakpoints dialog (Ctrl+Shift+F8) and select Edit description from the context menu. Now when you start typing a breakpoint's name, it gets the focus.
- Jump to source
-
To jump from the Breakpoints dialog to the line of code where the selected breakpoint is set, press F4.