LinqDataSourceStatusEventArgs.ExceptionHandled 屬性

定義

取得或設定值,這個值表示是否處理了例外狀況以及是否不應再度擲回此例外狀況。

public:
 property bool ExceptionHandled { bool get(); void set(bool value); };
public bool ExceptionHandled { get; set; }
member this.ExceptionHandled : bool with get, set
Public Property ExceptionHandled As Boolean

屬性值

如果例外狀況已處理則為 true,否則為 false

範例

下列範例顯示 事件的事件處理常式 Inserted 。 在事件處理常式中 Exception ,如果 屬性為 null ,則會從 屬性中的 Result 物件擷取產品識別碼。 產品識別碼是資料表的主鍵,而且是由資料庫設定,因此在插入作業完成之前,不會知道此值。 如果 屬性不等於 nullException 則會記錄例外狀況訊息。 屬性 ExceptionHandled 接著會設定為 true

protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception == null)
    {
        Product newProduct = (Product)e.Result;
        Literal1.Text = "The new product id is " + newProduct.ProductID;
        Literal1.Visible = true;            
    }
    else
    {
        LogError(e.Exception.Message);
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified.";
        Literal1.Visible = true;
        e.ExceptionHandled = true;            
    }
}
Protected Sub LinqDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs)
    If (IsNothing(e.Exception)) Then
        Dim newProduct As Product
        newProduct = CType(e.Result, Product)
        Literal1.Text = "The new product id is " & newProduct.ProductID
        Literal1.Visible = True
    Else
        LogError(e.Exception.Message)
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified."
        Literal1.Visible = True
        e.ExceptionHandled = True
    End If
End Sub

備註

您可以建立 、 DeletedInsertedSelectedUpdated 事件的事件處理常式 ContextCreated ,以檢查這些作業期間發生的任何例外狀況。 如果您處理例外狀況,而不想再次擲回例外狀況,請將 ExceptionHandled 屬性設定為 true 。 如果您未將 ExceptionHandled 屬性設定為 true ,例外狀況將會傳播至呼叫堆疊中的下一個事件處理常式。

適用於