Exception safety
Exception safety guarantees, originally formalized by David Abrahams, are a set of contractual guidelines that library implementers and clients can use when reasoning about exception handling safety in any programming language that uses exceptions, particularly C++.

There are several levels of exception safety (in decreasing order of safety):
# No-throw guarantee, also known as failure transparency: Operations are guaranteed to succeed and satisfy all requirements even in exceptional situations. If an exception occurs, it will be handled internally and not observed by clients.
# Strong exception safety, also known as commit or rollback semantics: Operations can fail, but failed operations are guaranteed to have no side effects, leaving the original values intact.
# Basic exception safety, also known as a no-leak guarantee: Partial execution of failed operations can result in side effects, but all invariants are preserved and there are no resource leaks (including memory leaks). Any stored data will contain valid values which may differ from the original values.
# No exception safety: No guarantees are made.

Usually, at least basic exception safety is required to write robust code in such languages. Higher levels of safety can sometimes be difficult to achieve, and might incur an overhead due to extra copying. A key mechanism for exception safety is a codice_1 clause, or similar exception handling syntax, which ensure that certain code is "always" run when a block is exited, including by exceptions. Several languages have constructs that simplify this, notably using the dispose pattern, named as codice_2, codice_3, or codice_4-with-resources.
Q5230580
David Abrahams
PER
Q471748
exception handling
Concept
Q2407
C++
MEDIA
Q188211
invariant
Concept
Q7315829
resource leak
Concept
Q751740
memory leak
Concept
Q5419496
exception handling syntax
Concept
Q5282669
dispose pattern
UNK
Q5419499
Exception safety
UNK
+1^^http://www.w3.org/2001/XMLSchema#decimal
1
NUMBER
+2^^http://www.w3.org/2001/XMLSchema#decimal
2
NUMBER
+3^^http://www.w3.org/2001/XMLSchema#decimal
3
NUMBER
+4^^http://www.w3.org/2001/XMLSchema#decimal
4
NUMBER
subclass of