Difference between revisions of "Cpp Coding Standards/ERR"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m
Line 2: Line 2:
 
How to distinguish and handle assertions, errors and exceptions.
 
How to distinguish and handle assertions, errors and exceptions.
 
----
 
----
=== Rules ===
+
=== Summary ===
 
+
 
==== AssertAssumptions ====
 
==== AssertAssumptions ====
 
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.
Line 24: Line 23:
 
Related Rules
 
Related Rules
 
* [[../META#ConsistentErrorHandling | META:ConsistentErrorHandling]]
 
* [[../META#ConsistentErrorHandling | META:ConsistentErrorHandling]]
 +
----
 +
=== Explanations ===
 +
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Revision as of 18:11, 27 November 2006

Eror Handling

How to distinguish and handle assertions, errors and exceptions.


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

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.

NeverFails

Destructors, delete operators and swap functions must never fail. Occurring exceptions have to be catched and handled within the same function.

Throwing

Throw exceptions by value, catch them by reference.

AvoidExceptionSpecs

Don't write exception specifications on your functions.

Exception: You cannot avoid them when overriding a virtual function that already has one.


Related Rules


Explanations


Personal tools