sunny123456

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

Idea的debug过程中,强制返回,避免操作资源

0、场景:我们平时使用debug排查问题,但是我们debug代码有进行一些数据库资源操作或缓存操作等,很显然。这时候,我们就可以使用idea中”Force Return“

代码

  1. public class BreakPointDemo {
  2. /**
  3. * 强制返回 | 避免操作资源
  4. */
  5. public static void forceReturn() {
  6. System.out.println("bug");
  7. //这里打断点
  8. System.out.println("定位到bug啦");
  9. System.out.println("db操作");
  10. System.out.println("redis操作");
  11. System.out.println("mq操作");
  12. }
  13. public static void main(String[] args) {
  14. forceReturn();
  15. }

1、打断点

2、 Force Return 操作 

3、看看控制台输出,没有Force Return后面的输出哦 

 4、一个误区,平时调试我们可能会想到,debug中途中,进行stop操作,达到上面的效果(错了)

5、看看输出,哦豁,重点来啦,全输出啦

            </div><div><div></div></div>
    </div>
</article>

原文链接:https://blog.csdn.net/u010675669/article/details/124225873

posted on 2025-07-16 09:25  sunny123456  阅读(108)  评论(0)    收藏  举报