LinqDataSourceStatusEventArgs.ExceptionHandled Egenskap

Definition

Hämtar eller anger ett värde som anger om undantaget hanterades och att det inte ska genereras igen.

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

Egenskapsvärde

trueom undantaget hanterades. annars . false

Exempel

I följande exempel visas en händelsehanterare för Inserted händelsen. Om egenskapen är Exceptioni händelsehanteraren null hämtas produkt-ID:t från objektet i Result egenskapen . Produkt-ID:t är en primärnyckel för tabellen och anges av databasen, därför är värdet inte känt förrän infogningsåtgärden har slutförts. Undantagsmeddelandet loggas om Exception egenskapen inte är lika med null. Egenskapen ExceptionHandled är sedan inställd på 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

Kommentarer

Du kan skapa händelsehanterare för ContextCreatedhändelserna , Deleted, Inserted, Selectedoch Updated för att undersöka eventuella undantag som inträffade under dessa åtgärder. Om du hanterar undantaget och inte vill att det ska genereras igen anger du ExceptionHandled egenskapen till true. Om du inte anger ExceptionHandled egenskapen till truesprids undantaget till nästa händelsehanterare i anropsstacken.

Gäller för