C ++错误处理 - 示例代码的良好来源? [英] C++ Error Handling -- Good Sources of Example Code?

查看:92
本文介绍了C ++错误处理 - 示例代码的良好来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于每一个示例代码,每个地方都忽略了错误处理(因为它混淆了示例代码正在寻址的问题)。我的编程知识主要来自书籍和网站,你很少看到任何错误处理在所有的使用,更不用说好东西。



哪里有一些地方可以看到C ++错误处理代码的好例子?具体的书籍,具体的开源项目(最好有文件和功能要查看)以及特定的网页或网站都将得到感激的接受。

解决方案

Herb Sutter's和Andrei Alexandrescu的书籍 C ++编码标准包含错误处理和异常的整个章节,包括




  • 自由地断言记录内部假设和不变量

  • 建立理性的错误处理政策,并严格按照

  • 区分错误和非错误

  • 设计并写错误安全代码

  • 喜欢使用例外来报告错误

  • 按价值分列,通过引用捕捉

  • 报告,处理和翻译错误

  • 避免异常规范



还包括一个例子a我发现它是一个非常有价值的资源。


Just about every piece of example code everywhere omits error handling (because it "confuses the issue" that the example code is addressing). My programming knowledge comes primarily from books and web sites, and you seldom see any error handling in use at all there, let alone good stuff.

Where are some places to see good examples of C++ error handling code? Specific books, specific open-source projects (preferably with the files and functions to look at), and specific web pages or sites will all be gratefully accepted.

解决方案

Herb Sutter's and Andrei Alexandrescu's book C++ Coding Standards comes with a whole chapter on Error Handling and Exceptions including

  • Assert liberally to document internal assumptions and invariants
  • Establish a rational error handling policy, and follow it strictly
  • Distinguish between errors and non-errors
  • Design and write error-safe code
  • Prefer to use exceptions to report errors
  • Throw by value, catch by reference
  • Report, handle, and translate errors appropriately
  • Avoid exception specifications

Every topic also includes an example and I found it to be a very valuable resource.

这篇关于C ++错误处理 - 示例代码的良好来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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