LinqDataSourceStatusEventArgs.Exception Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan pengecualian yang dilemparkan selama operasi data.
public:
property Exception ^ Exception { Exception ^ get(); };
public Exception Exception { get; }
member this.Exception : Exception
Public ReadOnly Property Exception As Exception
Nilai Properti
Objek Exception yang mewakili pengecualian, jika terjadi kesalahan; jika tidak, null
.
Contoh
Contoh berikut menunjukkan penanganan aktivitas untuk peristiwa tersebut Inserted . Di penanganan aktivitas, jika Exception properti adalah null
, ID produk diambil dari objek di Result properti . ID produk adalah kunci utama untuk tabel dan diatur oleh database, sehingga nilai tidak diketahui sampai operasi penyisipan selesai. Pesan pengecualian dicatat jika Exception properti tidak sama dengan null
. Properti ExceptionHandled kemudian diatur ke 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
Keterangan
Jika pengecualian dinaikkan selama operasi data, pengecualian disimpan di Exception properti . Anda dapat membuat penanganan aktivitas untuk ContextCreatedperistiwa , , Deleted, InsertedSelected, dan Updated dan dan mengambil pengecualian, jika ada, melalui Exception properti .