共用方式為


ListViewUpdatedEventArgs.Exception 屬性

定義

取得更新作業中引發的例外狀況 (如果有的話)。

public:
 property Exception ^ Exception { Exception ^ get(); };
public Exception Exception { get; }
member this.Exception : Exception
Public ReadOnly Property Exception As Exception

屬性值

Exception

在更新作業中引發的例外狀況 (如果有的話),而如果沒有引發例外狀況則為 null

範例

下列範例示範如何使用 Exception 屬性來判斷更新作業期間是否發生例外狀況。 此程式碼範例是針對 類別提供的較大範例的 ListViewUpdatedEventArgs 一部分。

void ContactsListView_ItemUpdated(Object sender, ListViewUpdatedEventArgs e)
{
    if (e.Exception != null)
    {
        if (e.AffectedRows == 0)
        {
            e.KeepInEditMode = true;
            Message.Text = "An exception occurred updating the contact. " +
                                "Please verify your values and try again.";
        }
        else
            Message.Text = "An exception occurred updating the contact. " +
                                "Please verify the values in the recently updated item.";

        e.ExceptionHandled = true;
    }
}
Sub ContactsListView_ItemUpdated(sender As Object, e As ListViewUpdatedEventArgs)
    If e.Exception IsNot Nothing Then
        If e.AffectedRows = 0 Then
            e.KeepInEditMode = True
            Message.Text = "An exception occurred updating the contact. " & _
                                "Please verify your values and try again."
        Else
            Message.Text = "An exception occurred updating the contact. " & _
                                "Please verify the values in the recently updated item."
        End If

        e.ExceptionHandled = True
    End If
End Sub

備註

Exception使用 屬性來判斷更新作業期間是否引發任何) (例外狀況。 如果沒有引發例外狀況,這個屬性會傳 null 回 。

注意

如果引發例外狀況,而且您在事件處理常式中處理例外狀況,請將 ExceptionHandled 屬性設定為 true 。 否則, ListView 控制項會重新擲回例外狀況。

適用於

另請參閱