Abrahams guarantees

From Wikipedia, the free encyclopedia

The Abrahams Guarantees are a set of contractual guidelines that class library implementors and clients use when reasoning about exception safety in C++ programs.

The rules apply to class implementations (components) in the presence of exceptions; they are as follows:

  • The basic guarantee: that the invariants of the component are preserved, and no resources are leaked.
  • The strong guarantee: that the operation has either completed successfully or thrown an exception, leaving the program state exactly as it was before the operation started.
  • The no-throw guarantee: that the operation will not throw an exception.

Code that doesn't follow one of the above rules is called exception unsafe.

The guarantees are named for David Abrahams, the member of the C++ Standard committee who formalized the guidelines.

[edit] references

  1. Abrahams, D. "Exception-Safety in Generic Components," Generic Programming: Proceedings of a Dagstuhl Seminar, M. Jazayeri, R. Loos, and D. Musser, eds. (Springer Verlag, 1999).