Exception safety
Exception safety is the state of code working correctly when exceptions are thrown.[src] To aid in ensuring exception safety, C++ standard library developers have devised a set of exception safety levels, contractual guarantees of the behavior of a data structure's operations with regard to exceptions.[src] Library implementers and clients can use these guarantees when reasoning about exception handling correctness.[src] The exception safety levels apply equally to other languages and error-handling mechanisms.[src]
Exception safety is the state of code working correctly when exceptions are thrown.[src] To aid in ensuring exception safety, C++ standard library developers have devised a set of exception safety levels, contractual guarantees of the behavior of a data structure's operations with regard to exceptions.[src] Library implementers and clients can use these guarantees when reasoning about exception handling correctness.[src] The exception safety levels apply equally to other languages and error-handling mechanisms.[src] The exception is caught and recovered from, or a finally block is entered The data structure with broken invariant is used by code that assumes the invariant, resulting in a bug Code with a bug such as the above can be said to be "exception unsafe".[src] Usually, at least basic exception safety is required to write robust code.[src] Higher levels of safety can sometimes be difficult to achieve, and might incur an overhead due to extra copying.[src] A key mechanism for exception safety is a finally clause, or similar exception handling syntax, which ensure that certain code is always run when a block is exited, including by exceptions.[src] Several languages have constructs that simplify this, notably using the dispose pattern, named as using (in C#), with (in Python), or try -with-resources (in Java).[src]
13 sentences · 13 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Exception safety." encyclopegia.org, 2026, https://encyclopegia.org/wiki/exception-safety. Accessed 03 December 2026.
Chicago
"Exception safety." encyclopegia.org. Accessed December 3, 2026. https://encyclopegia.org/wiki/exception-safety.
APA
encyclopegia.org. (2026). Exception safety. Retrieved December 3, 2026, from https://encyclopegia.org/wiki/exception-safety
Accessed December 3, 2026 · CC BY-SA 4.0 · citation page · JSON