Google 的 C++ style guide说“我们不使用异常(exception)”。该风格没有提到关于异常使用的 STL。由于 STL 分配器可能会失败,它们如何处理容器抛出的异常?
- 如果他们使用 STL,调用方如何获知分配失败?
push_back()
或 mapoperator[]
等 STL 方法不返回任何状态码。 - 如果他们不使用 STL,他们使用什么容器实现?
最佳答案
他们说他们不使用异常,并不是说没有人应该使用它们。如果你看看他们也写的理由:
Because most existing C++ code at Google is not prepared to deal with exceptions, it is comparatively difficult to adopt new code that generates exceptions.
常见的遗留问题。 :-(
关于c++ - Google C++ 风格指南的无异常(exception)规则; STL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5184115/