I agree with Evan. Since we don't control the environment, hardware, other software, etc, etc, that our product runs on, we have to be more careful with error checking than if we were writing server software. CHECK is an extreme measure - it's "gambling" with TerminateProcess/abort() - but also it can be expensive in terms of code size and cpu cycles.
On Tue, May 26, 2009 at 9:22 PM, Aaron Boodman <[email protected]> wrote: > > I get different stories about this all the time from different people. > It would be great to have them as part of the style guide so that I > can refer to it. > > One that you didn't cover is the invariant case. I originally used > DCHECKs, but it seems like if you're just going to crash on the next > line anyway, a CHECK makes more sense. I don't think it's that simple and I'd really not want to encourage devs to use CHECK simply as a guard for code that doesn't have error checks. > > > - a > > On Tue, May 26, 2009 at 5:01 PM, Evan Martin <[email protected]> wrote: > > > > In many places we have "shouldn't-happen" situations where a functon > > might return NULL or false. > > Coming from working on Google code you might be tempted to use > > CHECK(foobar != NULL). > > > > But in client software, things that should never happen end up > > happening all the time because of someone's strange computer setup or > > cosmic rays. Our pattern is: > > > > 1) If it is just "this is highly unlikely", attempt to recover from the > problem. > > 2) If it is "this shouldn't happen, and if it does a developer should > > learn about it", use something like > > if (!keyboard_has_spacebar) { > > NOTREACHED() << " this keyboard is crazy, maybe our detection code > > is wrong?"; > > return false; // attempt recovery anyway > > } > > 3) If it really is something that's so bad that it's a security > > problem if we continue, you should use CHECK(). But these should be > > very rare. > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: [email protected] View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---
