LinqDataSourceStatusEventArgs.Exception 속성

정의

데이터 작업 도중 throw된 예외를 가져옵니다.

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

속성 값

오류가 발생한 경우 예외를 나타내는 Exception 개체이고, 그렇지 않으면 null입니다.

예제

다음 예제에서는 이벤트 처리기는 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

설명

데이터 작업 중 예외가 발생 하는 경우 예외에 저장 됩니다는 Exception 속성입니다. 에 대 한 이벤트 처리기를 만들 수 있습니다는 ContextCreated, Deleted, Inserted, Selected, 및 Updated 이벤트 및 예외를 있는 경우 검색을 통해를 Exception 속성.

적용 대상