c++ - Google C++ 风格指南的无异常(exception)规则; STL?

标签 c++ exception stl

Google 的 C++ style guide说“我们不使用异常(exception)”。该风格没有提到关于异常使用的 STL。由于 STL 分配器可能会失败,它们如何处理容器抛出的异常?

  1. 如果他们使用 STL,调用方如何获知分配失败? push_back() 或 map operator[] 等 STL 方法不返回任何状态码。
  2. 如果他们不使用 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/

相关文章:

c++ - C++ 初学者 "while"程序

c# - 检索具有 CLSID 的组件的 COM 类工厂 - 类未注册

c++ - C++ 中的异构容器

c++ - 使用 std::map 的内存爆炸

c++ - std::list、std::vector 方法和 malloc()

c++ - 类 'is not a template type'

c++ - 从 Visual Studio 2010 运行 BOOST 单元测试

c++ - 什么时候加载 DLL : Implicit Linking VS Explicit Linking

exception - 如何捕获人脸 FileNotFoundException?

debugging - 如何在 x64 堆栈中找到 native 异常?