它通常用于移动语义组合具有很强的异常保证。
It is typically used to combine move semantics with strong exception guarantee.
这种方法保证将系统中的所有异常都报告给体系结构中的某个要素,并因此提供更高的系统可用性级别。
This approach ensured that any exception within the system could be reported to an element of the architecture which was able to provide a higher level of system availability.
而读取文件的代码应该检查这个版本号,以保证版本号小于或者等于当前版本,否则就会抛出一个异常。
And the code that reads the file should check to make sure that the version number is less than or equal to its current version and throw an exception if it's not.
So, summarizing better, assert is something you put in to say to the user, make sure you're giving me input of this type, but I'm going to guarantee you the rest of the code works correctly. Exceptions and exception handlers are saying, here are the odd cases that I might see and here's what I'd like to do in those cases in order to try and be able to deal with them.
所以更好的总结下,断言就是你放在那里告诉用户,保证你输入的是这种类型的,但我能保证剩下的代码运行正确,异常和异常处理做的事,这里有些我能预期的异常情况,并且这里有些情况,我能尝试处理。
应用推荐