C++ Error Handling — Good Sources of Example Code?

前端 未结 4 603
甜味超标
甜味超标 2020-12-23 02:38

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 come

4条回答
  •  感情败类
    2020-12-23 02:48

    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.

提交回复
热议问题