导致异常的递归原因是什么?

编程入门 行业动态 更新时间:2024-10-28 04:22:26
本文介绍了导致异常的递归原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在调试器中查看Java中的异常时,您会经常看到原因是无限循环的(我认为它是无限的)。

When looking at an exception in Java in a debugger you will often see that the cause is recursive to itself infinitely (I assume it's infinite).

eg: / p>

e.g:

Exception1, Caused by -> Exception2 Caused by -> Exception2 Caused by -> Exception2

为什么是这样?

strong> NB:这是在调试器中查看代码时,在这种情况下是Eclipse。

NB: This is when looking at the code in a debugger, Eclipse in this case.

推荐答案

在 Throwable的源代码:

187 /** 188 * The throwable that caused this throwable to get thrown, or null if this 189 * throwable was not caused by another throwable, or if the causative 190 * throwable is unknown. If this field is equal to this throwable itself, 191 * it indicates that the cause of this throwable has not yet been 192 * initialized. 193 * 194 * @serial 195 * @since 1.4 196 */ 197 private Throwable cause = this;

所以我猜你看到的是一个异常,没有使用一个构造函数一个原因。

So I guess what you are seeing is an Exception which was created without using one of the constructors which takes a cause.

您将在调试器中看到这一点,但 getCause 照顾不返回递归引用:

You will see this in a debugger, but getCause takes care of not returning the recursive reference:

414 public synchronized Throwable getCause() { 415 return (cause==this ? null : cause); 416 }

更多推荐

导致异常的递归原因是什么?

本文发布于:2023-10-08 14:04:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   异常   原因

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!