Difference between revisions of "Cpp Coding Standards/ERR/ExSpec"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m (typo)
Line 10: Line 10:
  
 
==== Exceptions ====
 
==== Exceptions ====
If you override a virtual function which has an exception specification in its base class, you need to do that in the overriding function, too - or to remove the exception specification in the base class. The exception specification in the overriding function needs to be at least as restrictive as th eone in the base class (it has to list the same, or less exceptions than the base class function).
+
If you override a virtual function which has an exception specification in its base class, you need to do that in the overriding function, too - or to remove the exception specification in the base class. The exception specification in the overriding function needs to be at least as restrictive as the one in the base class (it has to list the same, or less exceptions than the base class function).

Revision as of 12:45, 2 February 2007

Avoid Exception Specifications

Id: ERR:ExSpec

Summary

Don't write exception specifications on your functions.

Explanation

Exception specifications often do not what they are expected to do. They add overhead to the runtime. If they are triggered, they immediately terminate the program, which is often not the wanted behaviour. Therefore todays C++ experts leave them out.

Exceptions

If you override a virtual function which has an exception specification in its base class, you need to do that in the overriding function, too - or to remove the exception specification in the base class. The exception specification in the overriding function needs to be at least as restrictive as the one in the base class (it has to list the same, or less exceptions than the base class function).

Personal tools