Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>AException a = new AException (new BException ( new AException ) );</p> </blockquote> <p>This is legal.</p> <hr> <p>You can also initialize the cause directly using the <code>initCause(Throwable)</code> method.</p> <p>If you try to make exception its own cause; e.g.</p> <pre><code> AException a = new AException(); a.initCause(a); </code></pre> <p>you will get an <code>IllegalArgumentException("Self-causation not permitted")</code>. (Thanks to Joachim Sauer for pointing that out.)</p> <p>While, the JVM will not stop you creating an indirect cycle, it is a <strong>really bad idea</strong> nonetheless. </p> <ul> <li><p>It is an abuse of the <code>Throwable</code> API. It makes no logical sense for an exceptional event to have caused itself, directly or indirectly.</p></li> <li><p>There is likely be code out there that <em>assumes</em> that the "cause" chain of an exception doesn't have any cycles. Such code is likely to fail in a nasty way if it ever encounters a pathological exception with a cause cycle. </p></li> </ul> <p>Note that current generation (Java 7) <code>printStackTrace()</code> detects and deals with a "cause" cycles, but earlier generations did not:</p> <ul> <li><a href="http://srl.cs.berkeley.edu/~mhn/ftp/java/lang/Throwable.java.html" rel="nofollow">http://srl.cs.berkeley.edu/~mhn/ftp/java/lang/Throwable.java.html</a></li> <li><a href="http://javasourcecode.org/html/open-source/jdk/jdk-6u23/java.lang/Throwable.java.html" rel="nofollow">http://javasourcecode.org/html/open-source/jdk/jdk-6u23/java.lang/Throwable.java.html</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload