design by contract tests by assert or by exception?
今天也在考虑这个问题,google了下,投票最多的是:The rule of thumb is that you should use assertions when you are trying to catch your own errors, and exceptions when trying to catch other people's errors. In other words, you should use exceptions to check the preconditions for the public API functions, and whenever you get any data that are external to your system. You should use asserts for the functions or data that are internal to your system.
总结很精辟。
另一个是:
本文探讨了在软件开发中使用断言(assert)与异常(exception)的区别。总结指出,在检查内部系统的函数或数据时应使用断言,而在验证公共API的前置条件或处理外部数据时应使用异常。
519

被折叠的 条评论
为什么被折叠?



