I have a CreateValidator:
Protected Overrides Function CreateValidator() As IValidator
Return New ABC.DAL.ValidatorClasses.GeneralTypeValidator()
End Function
ValidatorClass:
Public Overrides Sub ValidateEntityBeforeSave(ByVal involvedEntity As IEntityCore)
Dim toValidate AsGeneralTypeEntity = CType(involvedEntity, GeneralTypeEntity)
If toValidate.GeneralType = "Abc" Then
Throw New ORMEntityValidationException("Abc is not valid General Type", toValidate)
End If
MyBase.ValidateEntityBeforeSave(involvedEntity)
End Sub
ButtonClick:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim da As New DataAccessAdapter
Dim entityGeneralType As New GeneralTypeEntity
entityGeneralType.GeneralType = "Abc"
Try
da.SaveEntity(entityGeneralType, True)
Catch ex As ORMEntityValidationException
Label1.Text = ex.Message
End Try
End Sub
When I click the Button, it throws the exception saying that it was not handled by the User code.
I handled it with Try... Catch and want to display it to the user using a Label.
Am I doing anything wrong?