LinqDataSourceStatusEventArgs.Exception Propriété

Définition

Obtient l'exception levée lors de l'opération de données.

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

Valeur de propriété

Objet Exception qui représente l'exception si une erreur s'est produite ; sinon, null.

Exemples

L’exemple suivant montre un gestionnaire d’événements pour l’événement Inserted . Dans le gestionnaire d’événements, si la Exception propriété est null, l’ID de produit est récupéré à partir de l’objet dans la Result propriété . L’ID de produit étant une clé primaire pour la table et défini par la base de données, la valeur n’est pas connue tant que l’opération d’insertion n’est pas terminée. Le message d’exception est journalisé si la Exception propriété n’est pas égale à null. La ExceptionHandled propriété est ensuite définie sur 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

Remarques

Si une exception est levée pendant l’opération de données, l’exception est stockée dans la Exception propriété . Vous pouvez créer des gestionnaires d’événements pour les ContextCreatedévénements , Deleted, Inserted, Selectedet Updated et et récupérer l’exception, le cas échéant, via la Exception propriété .

S’applique à