本文介绍了导致异常的递归原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在调试器中查看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 }更多推荐
导致异常的递归原因是什么?
发布评论