Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Google deals with errors in C++

Tags:

c++

exception

Google does not use exception in their C++ code base. For errors, they use a class called status than the programmer must check when it is returned from a function. Otherwise the program does not compile (link https://www.youtube.com/watch?v=NOCElcMcFik at 41:34). I have a few questions:

1) Is there any example of that class on the web freely available?

2) That's okay for "void f()" that work with side effects that you turn into a "Status f()". But what if your function already returns a value? Google does not allow to pass references that are not const so you can't mutate a Status object given to you. So how do they do?

Thanks for your help.

like image 552
InsideLoop Avatar asked Apr 28 '15 15:04

InsideLoop


1 Answers

From Google style guide:

Input parameters are usually values or const references, while output and input/output parameters will be non-const pointers.

As the lecturer said Google uses a proprietary in-house compiler that has been rigged to throw errors when Status isn't checked.

like image 87
Benjy Kessler Avatar answered Sep 28 '22 23:09

Benjy Kessler