如何避免在C ++中使用异常? [英] How can I avoid using exceptions in C++?
本文介绍了如何避免在C ++中使用异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用哪些技巧来避免C ++中的异常,如 Google风格指南?
What techniques can I use to avoid exceptions in C++, as mentioned in Google's style guide?
推荐答案
- 不要使用STL(严重依赖于异常)。
- 仅使用
new(std :: nothrow)
或替换:: operator new
以在失败时返回0.
- Don't throw exceptions.
- Don't use STL (which relies heavily on exceptions).
- Use only
new(std::nothrow)
or override::operator new
to return 0 on failure.
请注意,通过避免异常,你实际上抛出了很多有用的库,包括Boost。基本上,你必须从头开始编程。
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.
这篇关于如何避免在C ++中使用异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文