Is it a good practice to throw an exception on Validate() methods or better to return bool value?

后端 未结 8 1854
攒了一身酷
攒了一身酷 2020-12-28 14:24

Is it recommended or not to throw exceptions from Validation methods like:

ValidateDates();
ValidateCargoDetails();

Apart from this : Is t

相关标签:
8条回答
  • 2020-12-28 14:50

    I would say it all depends on what/how you are doing the validation. But at the end of the day a developer can always choose to ignore a returned result (this is the problem with them), they can't ignore an exception without writing explicit code to do so.

    0 讨论(0)
  • 2020-12-28 14:52

    I would suggest returning a ValidationResult object containing ValidationFailures. You should never use exceptions as part of your logical coding. Exceptions are for exceptions

    0 讨论(0)
提交回复
热议问题