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

后端 未结 8 1901
攒了一身酷
攒了一身酷 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:26

    Throwing exception must not be used to control the flow of the application. As the name implies, it happens in exceptional cases while validation could commonly fail. They are also expensive and impact the performance.

    I would go with returning a boolean plus a string for reason.

提交回复
热议问题