Difference between revisions of "Cpp Coding Standards/ERR"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Eror Handling ==
+
== Error Handling (ERR) ==
How to distinguish and handle assertions, errors and exceptions.
+
''How to distinguish and use exceptions, assertions and other error cases.''
----
+
=== Summary ===
+
==== AssertAssumptions ====
+
Assert liberally to document internal assumptions and invariants. Don't use assertions for runtime errors.
+
Ensure that assertions don't perform side effects.
+
  
==== Guarantee ====
+
===== Assert Assumptions <span id="Assert">(Assert)</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.
+
Assert liberally to document internal assumptions and invariants. Don't use assertions for runtime errors.<br>
 +
Ensure that assertions don't perform side effects.<br>
 +
[[/Assert|-> Details]]
  
==== NeverFails ====
+
===== Function Safety Guarantees <span id="Safe">(Safe)</span> =====
Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function.
+
Provide the strongest error-safety guarantee for each function that does not punish callers who do not need it. The basic guarantee is always necessary. [[/Safe|-> Details]]
  
==== Throwing ====
+
===== Which Functions Never Fail <span id="NoFail">(NoFail)</span> =====
Throw exceptions by value, catch them by reference.
+
Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function. [[/NoFail|-> Details]]
  
==== AvoidExceptionSpecs ====
+
===== Throwing and Catching Exceptions <span id="HowThrow">(HowThrow)</span> =====
Don't write exception specifications on your functions.  
+
Throw exceptions by value, catch them by reference. [[/HowThrow|-> Details]]
  
Exception: You cannot avoid them when overriding a virtual function that already has one.
+
===== Avoid Exception Specifications <span id="ExSpec">(ExSpec)</span> =====
----
+
Don't write exception specifications on your functions. [[/ExSpec|-> Details]]
Related Rules
+
* [[../META#ConsistentErrorHandling | META:ConsistentErrorHandling]]
+
----
+
=== Explanations ===
+
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Latest revision as of 09:05, 23 May 2007

Error Handling (ERR)

How to distinguish and use exceptions, assertions and other error cases.

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.
-> Details

Function Safety Guarantees (Safe)

Provide the strongest error-safety guarantee for each function that does not punish callers who do not need it. The basic guarantee is always necessary. -> Details

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. -> Details

Throwing and Catching Exceptions (HowThrow)

Throw exceptions by value, catch them by reference. -> Details

Avoid Exception Specifications (ExSpec)

Don't write exception specifications on your functions. -> Details


Personal tools