如何避免在C ++中使用异常? [英] How can I avoid using exceptions in C++?

查看:131
本文介绍了如何避免在C ++中使用异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用什么技术来避免C ++中的异常,如 Google风格指南

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

推荐答案


  1. 不要抛出异常

  2. 不要使用STL(严重依赖于异常)。

  3. 仅使用 new(std :: nothrow )或覆盖 :: operator new 在失败时返回0。

  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.

请注意,通过避免异常,您可以有效地抛出许多有用的库,包括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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆