How can I avoid using exceptions in C++?

后端 未结 6 1779
臣服心动
臣服心动 2021-02-04 21:08

What techniques can I use to avoid exceptions in C++, as mentioned in Google\'s style guide?

6条回答
  •  北海茫月
    2021-02-04 21:31

    1. Don't throw exceptions.
    2. Don't use STL (which relies heavily on exceptions).
    3. Use only new(std::nothrow) or override ::operator new to return 0 on failure.

    Note that by avoiding exceptions, you're effectively throwing out lots of useful libraries, including Boost. Basically, you'll have to program everything from scratch.

提交回复
热议问题