次の方法で共有


Throwable.InitCause(Throwable) Method

Definition

Initializes the cause of this throwable to the specified value.

[Android.Runtime.Register("initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;", "GetInitCause_Ljava_lang_Throwable_Handler")]
public virtual Java.Lang.Throwable InitCause (Java.Lang.Throwable? cause);
[<Android.Runtime.Register("initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;", "GetInitCause_Ljava_lang_Throwable_Handler")>]
abstract member InitCause : Java.Lang.Throwable -> Java.Lang.Throwable
override this.InitCause : Java.Lang.Throwable -> Java.Lang.Throwable

Parameters

cause
Throwable

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.)

Returns

a reference to this Throwable instance.

Attributes

Exceptions

if Throwable is this object.

if the cause has already been initialized.

Remarks

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
            }

Added in 1.4.

Java documentation for java.lang.Throwable.initCause(java.lang.Throwable).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to