Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 "int a = b+2;" and go immidiatly to "System.out.prinln(a);"?

P.S. I use Intellij Idea 12.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...