当前位置: 动力学知识库 > 问答 > 编程问答 >

How to pause a java program in eclipse by code

问题描述:

Is there any java code, which can make a java program pause in eclipse debugger, just like breakpoint? Then I can check the information of debugger, like values, stack.

Someone may misunderstand my question. I often write code for debugging like this

if(some_condition){

print_log();

abort();

}

In Visual Studio, I write abort() function. When I run a program in debug mode, abort() function can make the program pause and I can check the debugger.Is there some function in java like abort() in C++?

网友答案:

I think you'll want to use conditional breakpoints. I guess you don't want to define a beakpoint which will block your program each it passes on a given line, but only when specific condition occur.

So define a breakpoint, and add a boolean condition to it. You may for example define some variable like :

boolean must_break = false;

Then later on

if (some_condition) { must_break = true; }

Just set you breakpoint on any line with

must_break=false

That way, you control when you want to break you program's execution, and the must_break condition is reset for the next time.

分享给朋友:
您可能感兴趣的文章:
随机阅读: