Possible Bug with PropertyHasChanged?

Possible Bug with PropertyHasChanged?

Old forum URL: forums.lhotka.net/forums/t/4414.aspx


dlabar posted on Tuesday, February 26, 2008

I found an interesting issue when updating a property databound to a Textbox.

My BO has an email address databound to a textbox.  I have a self defined Validation rule that the email address has to be unique.  So if I change the email address to a value that already exists, the PropertyHasChanged function will call ValidationRules.CheckRules(), and an execption will get thrown.  The PropertyHasChanged doesn't catch this exception, so the MarkDirty is never called.  This results in a new value in my BO, but isDirty is still false.

 

I use isDirty on my Cancel method to determine if I need to do anything.  Even though the user has change the e-mail address, because of the exception, pressing Cancel doesn't work.

 

I'm thinking PropertyHasChanged should have a Try Catch Finaly Statement.  With the CheckRules in the try, the Catch, just rethrowing the exception and the finally calling MarkDirty and Property has changed.

RockfordLhotka replied on Tuesday, February 26, 2008

Rule methods should never throw exceptions. If an exception occurs in a rule method, that's a bug in the rule method.

dlabar replied on Tuesday, February 26, 2008

Well that was dumb of me.  I was trapping and discarding the exception without notifying the user, so I never saw the error.  Thanks.

Copyright (c) Marimer LLC