Bagikan melalui


LinqDataSourceStatusEventArgs.ExceptionHandled Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah pengecualian ditangani dan tidak boleh dilemparkan lagi.

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

Nilai Properti

true jika pengecualian ditangani; jika tidak, false.

Contoh

Contoh berikut menunjukkan penanganan aktivitas untuk peristiwa tersebut Inserted . Di penanganan aktivitas, jika Exception properti adalah null, ID produk diambil dari objek di Result properti . ID produk adalah kunci primer untuk tabel dan diatur oleh database, oleh karena itu nilai tidak diketahui sampai operasi penyisipan selesai. Pesan pengecualian dicatat jika Exception properti tidak sama dengan null. Properti ExceptionHandled kemudian diatur ke 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

Keterangan

Anda dapat membuat penanganan aktivitas untuk ContextCreatedperistiwa , , DeletedInserted, Selected, dan Updated untuk memeriksa pengecualian apa pun yang terjadi selama operasi tersebut. Jika Anda menangani pengecualian dan tidak ingin dilemparkan lagi, atur ExceptionHandled properti ke true. Jika Anda tidak mengatur ExceptionHandled properti ke true, pengecualian akan disebarluaskan ke penanganan aktivitas berikutnya di tumpukan panggilan.

Berlaku untuk