Difference between revisions of "Cpp Coding Standards/ERR"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Cpp Coding Standards/Topics/ERR moved to Cpp Coding Standards/Error Handling: Improve Cpp_Coding_Standards structure.)
Line 1: Line 1:
== Eror Handling ==
+
Topic-Id: '''ERR'''
How to distinguish and handle assertions, errors and exceptions.
+
 
 +
How to distinguish and use exceptions, assertions and other error cases.
 +
 
 
----
 
----
 
=== Summary ===
 
=== Summary ===
==== AssertAssumptions ====
+
==== 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.
  
==== Guarantee ====
+
[[/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.
  
==== NeverFails ====
+
[[/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.
  
==== AvoidExceptionSpecs ====
+
[[/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
* [[../META#ConsistentErrorHandling | META:ConsistentErrorHandling]]
+
* [[../Principles#ErrHdl |PRINC:ErrHdl]] - Consistent Error Handling
----
+
=== Explanations ===
+
  
 
----
 
----
 
[[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.


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.

Details

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.

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.

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

Details


Related Rules


Personal tools