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

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

    I usually use visitor pattern for validating input; accumulating all the errors into a list or something to show the user. The logic goes like, checking the list for validation errors, if found, inform the user, otherwise good to go.

    IMO, validation errors are not something exceptional, hence it should not be dealt like one.

提交回复
热议问题