I have trouble handlling exceptions.
My code:
Try
Dim o As New StoreItemsEntity()
With o
.Fields("StoreItemId").ForcedCurrentValueWrite(storeItemId)
.IsNew = False
.StoreItemTypeId = submittedValues(StoreItemsFields.StoreItemTypeId.Alias)
.CustomerId = submittedValues(StoreItemsFields.CustomerId.Alias)
.StoreItemUniqueId = submittedValues(StoreItemsFields.StoreItemUniqueId.Alias)
.StoreItem = submittedValues(StoreItemsFields.StoreItem.Alias)
.StoreItemDeployable = submittedValues(StoreItemsFields.StoreItemDeployable.Alias)
.StoreItemDescription = submittedValues(StoreItemsFields.StoreItemDescription.Alias)
End With
o.Save()
Catch ex As System.Data.SqlClient.SqlException
If ex.Message.Contains("Cannot insert duplicate key row in object") Then
Dim msg As New LiteralControl("<div style='color:red;padding:3px 3px 3px 3px;'>Cannot insert duplicate key row in object. Make sure that the Item identification is unique to the customer<div>")
rg.Controls.Add(msg)
Else
Throw New Exception(ex.Message, ex.InnerException)
End If
End Try
Regardless of the try/catch an exception is thrown deeper down in the code:
Server Error in '/InStoreChamp' Application.
--------------------------------------------------------------------------------
Cannot insert duplicate key row in object 'dbo.StoreItems' with unique index 'UC_StoreItems'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object 'dbo.StoreItems' with unique index 'UC_StoreItems'.
The statement has been terminated.
Source Error:
Line 703: Protected Overrides Overloads Function UpdateEntity() As Boolean
Line 704: Dim dao As StoreItemsDAO = CType(CreateDAOInstance(), StoreItemsDAO)
Line 705: Return dao.UpdateExisting(MyBase.Fields, MyBase.Transaction)
Line 706: End Function
Line 707:
Source File: C:\Visual Studio 2008\Projects\myproject\myproject.DLL\EntityClasses\StoreItemsEntity.vb Line: 705
What am I doing wrong?