LinqDataSourceStatusEventArgs.ExceptionHandled Proprietà

Definizione

Ottiene o imposta un valore che indica se l'eccezione è stata gestita e non deve essere nuovamente generata.

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

Valore della proprietà

true se l'eccezione è stata gestita; in caso contrario, false.

Esempio

Nell'esempio seguente viene illustrato un gestore eventi per l'evento Inserted . Nel gestore eventi, se la Exception proprietà è null, l'ID prodotto viene recuperato dall'oggetto nella Result proprietà . L'ID prodotto è una chiave primaria per la tabella e viene impostata dal database, pertanto il valore non è noto fino al termine dell'operazione di inserimento. Il messaggio di eccezione viene registrato se la Exception proprietà non è uguale a null. La ExceptionHandled proprietà viene quindi impostata su 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

Commenti

È possibile creare gestori eventi per gli ContextCreatedeventi , Deleted, Inserted, Selectede Updated per esaminare eventuali eccezioni che si sono verificate durante queste operazioni. Se si gestisce l'eccezione e non si vuole che venga generata di nuovo, impostare la ExceptionHandled proprietà su true. Se non si imposta la ExceptionHandled proprietà su true, l'eccezione verrà propagata al gestore eventi successivo nello stack di chiamate.

Si applica a