4 ms·
The Google C++ style [1] guide bans exceptions entirely and strongly advises against RTTI. [1] https://google.github.io/styleguide/cppguide.html https://google
by toby 10y ago
The Google C++ style [1] guide bans exceptions entirely and strongly advises against RTTI.
[1] https://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html
- nomel 10y agoThis link is constantly misused. Their reason is having to support legacy code that can't handle exceptions. That's it. From that link: "However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. 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." Would the use exceptions if they could do it again?
- vvanders 10y agoLLVM [1] has very similar restrictions for different reasons. [1] http://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or-exceptions http://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or...
- amaks 10y agoNo. The reason they don't use exceptions is because they lead to unreliable code that is difficult to maintain. There are other ways to indicate error situations such as returning error result that caller must handle.
- maxlybbert 10y agoFrom the Google style guide (section on exceptions): "On their face, the benefits of using exceptions outweigh the costs, especially in new projects. However, for existing code, the introduction of exceptions has implications on all dependent code. If exceptions can be propagated beyond a new project, it also becomes problematic to integrate the new project into existing exception-free code. 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. "Given that Google's existing code is not exception-tolerant, the costs of using exceptions are somewhat greater than the costs in a new project. The conversion process would be slow and error-prone. We don't believe that the available alternatives to exceptions, such as error codes and assertions, introduce a significant burden. "Our advice against using exceptions is not predicated on philosophical or moral grounds, but practical ones. ... Things would probably be different if we had to do it all over again from scratch."