Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to get thrown.)
This method can be called at most once. It is generally called from
within the constructor, or immediately after creating the
throwable. If this throwable was created
with Throwable(Throwable)
or
Throwable(String,Throwable)
, this method cannot be called
even once.
An example of using this method on a legacy throwable type without other support for setting the cause is:
try { lowLevelOp(); } catch (LowLevelException le) { throw (HighLevelException) new HighLevelException().initCause(le); // Legacy constructor }
cause | the cause (which is saved for later retrieval by the
getCause() method). (A null value is
permitted, and indicates that the cause is nonexistent or
unknown.) |
Throwable
instance.
IllegalArgumentException | if cause is this
throwable. (A throwable cannot be its own cause.) | |
IllegalStateException | if this throwable was
created with Throwable(Throwable) or
Throwable(String,Throwable) , or this method has already
been called on this throwable. |
Diagram: Exceptions