System.Diagnostics.Debugger.Break() like using java?

自古美人都是妖i 提交于 2020-01-01 23:14:49

问题


Is there a method to signal a breakpoint in Java like System.Diagnostics.Debugger.Break() in C#?


回答1:


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.




回答2:


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.




回答3:


How about throwing and catching a specific Exception for this purpose and creating an Exception breakpoint in your IDE ?




回答4:


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.



来源:https://stackoverflow.com/questions/2840941/system-diagnostics-debugger-break-like-using-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!