Idea的debug过程中,强制返回,避免操作资源
0、场景:我们平时使用debug排查问题,但是我们debug代码有进行一些数据库资源操作或缓存操作等,很显然。这时候,我们就可以使用idea中”Force Return“
代码
- public class BreakPointDemo {
-
- /**
- * 强制返回 | 避免操作资源
- */
- public static void forceReturn() {
- System.out.println("bug");
-
- //这里打断点
- System.out.println("定位到bug啦");
-
- System.out.println("db操作");
- System.out.println("redis操作");
- System.out.println("mq操作");
- }
-
- public static void main(String[] args) {
-
- forceReturn();
- }
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

浙公网安备 33010602011771号