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製品 ID は プロパティの Result オブジェクトから取得されます。 製品 ID はテーブルの主キーであり、データベースによって設定されるため、挿入操作が完了するまで値は認識されません。 プロパティが と等しくない場合、 Exception 例外メッセージがログに null記録されます。 その後、 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

注釈

、および イベントのイベント ハンドラーをContextCreatedSelectedDeletedInserted作成して、Updatedそれらの操作中に発生した例外を調べることができます。 例外を処理し、再度スローしたくない場合は、 プロパティを ExceptionHandledtrue設定します。 プロパティを にExceptionHandledtrue設定しない場合、例外は呼び出し履歴の次のイベント ハンドラーに反映されます。

適用対象