Search code examples
javadebuggingintellij-idea

How skip line in Intellij idea debug?


Suppose I have java code like this (only as Example):

public void someMethod(){
    int a = 3;
    int b = 2; // <-- stay debug here
    a = b + 2;
    System.out.prinln(a);
}

It is possible to skip execution of line a = b + 2; and go immidiatly to System.out.prinln(a);?

P.S. I use Intellij Idea 12.


Solution

  • It's not possible with the debugger to not execute parts of the code.

    It is however possible to execute extra code and change values on variables so if you need to exclude one row from execution during debug you will have to alter your code to prepare for that kind of debugging.

    public void someMethod() {
        int a = 3;
        int b = 2;
        boolean shouldRun = true;
        if (shouldRun) {
            a = b + 2;
        }
        System.out.prinln(a);
    }
    

    You would then set a break point that changes the value of shouldRun without stopping execution. It can be done like this.

    enter image description here

    Note that

    1. Suspend isn't checked
    2. Log evaluated expression is used to alter a variable when the break point is hit