LinqDataSourceStatusEventArgs.Exception LinqDataSourceStatusEventArgs.Exception LinqDataSourceStatusEventArgs.Exception LinqDataSourceStatusEventArgs.Exception Property


データ操作時にスローされた例外を取得します。Gets the exception that was thrown during the data operation.

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


エラーが発生した場合は、例外を表す Exception オブジェクト。それ以外の場合は、nullAn Exception object that represents the exception, if an error occurred; otherwise, null.

次の例は、イベント ハンドラーをInsertedイベント。The following example shows an event handler for the Inserted event. イベント ハンドラーの場合、Exceptionプロパティはnull、製品内のオブジェクトから ID を取得、Resultプロパティ。In the event handler, if the Exception property is null, the product ID is retrieved from the object in the Result property. 製品 ID は、テーブルの主キーし、データベースによって設定されるため、挿入操作が完了するまで、値が不明です。The product ID is a primary key for the table and is set by the database, so the value is not known until the insert operation has finished. 場合に例外メッセージがログ記録、Exceptionプロパティが等しくないnullします。The exception message is logged if the Exception property is not equal to null. ExceptionHandledプロパティに設定し、trueします。The ExceptionHandled property is then set to 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;            
        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
        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


例外が格納されているデータの処理中に例外が発生する場合、Exceptionプロパティ。If an exception is raised during the data operation, the exception is stored in the Exception property. イベント ハンドラーを作成することができます、 ContextCreatedDeletedInsertedSelected、およびUpdatedイベントを取得、存在する場合は、例外を通じて、Exceptionプロパティ。You can create event handlers for the ContextCreated, Deleted, Inserted, Selected, and Updated events and retrieve the exception, if any, through the Exception property.