它是扔在验证()方法或更好的异常返回布尔值,一个好的做法? [英] Is it a good practice to throw an exception on Validate() methods or better to return bool value?

查看:198
本文介绍了它是扔在验证()方法或更好的异常返回布尔值,一个好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是建议还是不要扔像验证方法例外:

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

ValidateDates();
ValidateCargoDetails();



除了这个:有一个强大的验证设计模式经常使用?

Apart from this : Is there a robust validation design pattern often used?

感谢

推荐答案

我会建议返回一个包含ValidationFailures一个为ValidationResult对象。
你不应该使用的例外,你的逻辑编码的一部分。例外的是例外

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

这篇关于它是扔在验证()方法或更好的异常返回布尔值,一个好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆