Difference between revisions of "Cpp Coding Standards/ERR"
m (Cpp Coding Standards/Topics/ERR moved to Cpp Coding Standards/Error Handling: Improve Cpp_Coding_Standards structure.) |
|||
Line 1: | Line 1: | ||
− | + | Topic-Id: '''ERR''' | |
− | How to distinguish and | + | |
+ | How to distinguish and use exceptions, assertions and other error cases. | ||
+ | |||
---- | ---- | ||
=== Summary === | === Summary === | ||
− | ==== | + | ==== Assert Assumptions <span id="Assert">(Assert)</span> ==== |
Assert liberally to document internal assumptions and invariants. Don't use assertions for runtime errors. | Assert liberally to document internal assumptions and invariants. Don't use assertions for runtime errors. | ||
Ensure that assertions don't perform side effects. | Ensure that assertions don't perform side effects. | ||
− | ==== | + | [[/Assert|Details]] |
+ | |||
+ | ==== Function Safety Guarantees <span id="Safe">(Safe)</span> ==== | ||
For each function, give the strongest error-safety guarantee that won't penalize callers who don't need it. Always give at least the basic guarantee. | For each function, give the strongest error-safety guarantee that won't penalize callers who don't need it. Always give at least the basic guarantee. | ||
− | ==== | + | [[/Safe|Details]] |
+ | |||
+ | ==== Which Functions Never Fail <span id="NoFail">(NoFail)</span> ==== | ||
Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function. | Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function. | ||
− | ==== Throwing ==== | + | [[/NoFail|Details]] |
+ | |||
+ | ==== Throwing and Catching Exceptions <span id="HowThrow">(HowThrow)</span> ==== | ||
Throw exceptions by value, catch them by reference. | Throw exceptions by value, catch them by reference. | ||
− | ==== | + | [[/HowThrow|Details]] |
+ | |||
+ | ==== Avoid Exception Specifications <span id="ExSpec">(ExSpec)</span> ==== | ||
Don't write exception specifications on your functions. | Don't write exception specifications on your functions. | ||
Exception: You cannot avoid them when overriding a virtual function that already has one. | Exception: You cannot avoid them when overriding a virtual function that already has one. | ||
+ | |||
+ | [[/ExSpec|Details]] | ||
+ | |||
---- | ---- | ||
Related Rules | Related Rules | ||
− | * [[../ | + | * [[../Principles#ErrHdl |PRINC:ErrHdl]] - Consistent Error Handling |
− | - | + | |
− | + | ||
---- | ---- | ||
[[Category:Coding Standards]] | [[Category:Coding Standards]] |
Revision as of 17:46, 29 November 2006
Topic-Id: ERR
How to distinguish and use exceptions, assertions and other error cases.
Contents
Summary
Assert Assumptions (Assert)
Assert liberally to document internal assumptions and invariants. Don't use assertions for runtime errors. Ensure that assertions don't perform side effects.
Function Safety Guarantees (Safe)
For each function, give the strongest error-safety guarantee that won't penalize callers who don't need it. Always give at least the basic guarantee.
Which Functions Never Fail (NoFail)
Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function.
Throwing and Catching Exceptions (HowThrow)
Throw exceptions by value, catch them by reference.
Avoid Exception Specifications (ExSpec)
Don't write exception specifications on your functions.
Exception: You cannot avoid them when overriding a virtual function that already has one.
Related Rules
- PRINC:ErrHdl - Consistent Error Handling