Skip to main content
12 events
when toggle format what by license comment
Feb 25, 2016 at 8:55 comment added JacquesB This is the correct answer!
Feb 16, 2016 at 15:08 comment added Christian Sauer Perhaps a better example for save might be a problem with the backend, e. g. the server is down - exceptional as hell
Feb 16, 2016 at 0:46 comment added kevin cline Perhaps a more formal expression might be: An exception is when a method is unable to satisfy it's post-condition.
Feb 15, 2016 at 22:15 history edited Theo Lenndorff CC BY-SA 3.0
fixed spelling and grammar, remove empty phrases to get straight to the point
Oct 29, 2015 at 1:32 comment added Andy This is better than the accepted answer i think. Throw when the call can't do the thing it was supposed to do.
Dec 16, 2014 at 10:36 comment added flodin Another problem with this approach is that it can only be used if you are sure that there will be no interference from other threads or processes that might affect the validation result. By the time you call Save, the personData may no longer be valid.
Nov 19, 2013 at 13:53 comment added Phil @Heinzi I agree. It could be refactored so that Validate() is called inside the Save() method, and specific details from the ValidationResult could be used to construct an appropriate message for the exception.
Oct 21, 2013 at 9:27 comment added Heinzi Nice idea! One drawback: In your example, validation is actually performed twice: Once during Validate (returning False if invalid) and once during Save (throwing a specific, well-documented exception if invalid). Of course, the validation result could be cached inside the object, but that would add additional complexity, since the validation result would need to be invalidated on changes.
Jan 24, 2013 at 13:21 comment added Theo Lenndorff It does not help to answer your question, but I just like to point out that you implicitly or purposely followed the Command-query separation principle (en.wikipedia.org/wiki/Command-query_separation). ;-)
Jan 24, 2013 at 13:14 comment added paul Just yesterday I made a struct called "ValidationResult" and structured my code the way you describe.
Jan 24, 2013 at 13:14 history edited Theo Lenndorff CC BY-SA 3.0
added 15 characters in body
Jan 24, 2013 at 13:05 history answered Theo Lenndorff CC BY-SA 3.0