Is there a method to signal a breakpoint in Java like开发者_开发知识库 System.Diagnostics.Debugger.Break() in C#?
yes I wanted something like this, so I implemented a pretty simple solution from my C days. This may be useful if you want a lightweight answer.
public class DebugHelper
{
public static breakHere()
{
int i = 0; // Set breakpoint on this line in your IDE
}
}
To use this method. Put a breakpoint in your code on the "int i = 0;" line. And call that method in the code you are debugging. It is a quick answer to getting some dynamic debugging and faster than a watch on a variable.
Example ...
private something(...)
{
for( ... )
{
if( null == value ) DebugHelper.breakHere();
}
}
Of course in C, you can put the right ASM breakpoint instruction ;-) This works fine for me on the rare occasions I want something like this.
Not really. But I assume it can be implemented by accessing the debugging interface through an interface and set the breakpoint to the current class where the Break() function is implemented. Interesting question though.
How about throwing and catching a specific Exception for this purpose and creating an Exception breakpoint in your IDE ?
Usually break points are a feature offered by the IDE being used itself. Maybe you could take a look at the Java Platform Debugger Architecture.
精彩评论