Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google C++ style guide's No-exceptions rule; STL?

Tags:

c++

exception

stl

Google's C++ style guide says "We do not use exceptions". The style does not mention STL with respect to usage of exception. Since STL allocators can fail, how do they handle exceptions thrown by containers?

  1. If they use STL, how is the caller informed of allocation failures? STL methods like push_back() or map operator[] do not return any status codes.
  2. If they do not use STL, what container implementation do they use?
like image 556
Andrei Avatar asked Mar 03 '11 17:03

Andrei


1 Answers

They say that they don't use exceptions, not that nobody should use them. If you look at the rationale they also write:

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.

The usual legacy problem. :-(

like image 68
Bo Persson Avatar answered Sep 28 '22 07:09

Bo Persson