3 ms·
I've used exceptions for flow control in validation before. Worked well. Basically, you have nested validation code, and the second you hit something which in
by AndrewDucker 14y ago
I've used exceptions for flow control in validation before. Worked well.
Basically, you have nested validation code, and the second you hit something which invalidates your data you throw an InvalidDataException(X), catch it at the top of the validation, and then report back to the user that their input is broken because of X.
The alternative was that every method would need to pass back whether it had found a validation error, and every place that called one would need to check that returned value. Huge numbers of lines of code, for no real gain.
(Obviously, this doesn't work if you want to return _all_ the things that are wrong with the data.)
- deleted 14y ago[deleted]