您的位置:首页 > 编程语言 > C语言/C++

C++库研究笔记——使用assert还是exception?

2013-09-29 23:16 246 查看


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.

总结很精辟。

另一个是:


Exception vs Assert? [duplicate]

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: