What causes a recursive reason for the exception?

When considering an exception in Java in the debugger, you often see that the reason is recursive for itself infinitely (I assume that it is infinite).

eg:

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

Why is this?

NB: This is when viewing the code in the debugger, Eclipse in this case.

+6
source share
1 answer

Looking at the Throwable source code :

  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 assume that you are seeing this Exception that was thrown without using one of the constructors that accepts the reason.

You will see this in the debugger, but getCause takes care not to return a recursive link:

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

Source: https://habr.com/ru/post/919327/


All Articles