Exception safety
Exception safety guarantees are a set of contractual guidelines that library implementers and clients can use when reasoning about exception handling correctness. The guarantees presented here originated out of work on C++, but apply equally to other languages and error-handling mechanisms. History. As David Abrahams writes, "nobody ever spoke of 'error-safety' before C++ had exceptions." The term appeared as the topic of publications in JTC1/SC22/WG21, the C++ standard committee, as early as 1994. Exception safety for the standard library was first formalized for STLport by Abrahams, establishing the basic safety/strong safety distinction. This  was extended to the modern basic/strong/nothrow guarantees in a later proposal. Classification. The C++ standard library provides several levels of exception safety (in decreasing order of safety): Usually, at least basic exception safety is required to write robust code. 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. Example. Consider a smart vector type, such as C++'s or Java's . When an item is added to a vector , the vector must actually add to the internal list of objects and update a count field that says how many objects are in . It may also need to allocate new memory if the existing capacity isn't sufficient. Exception safety alternatives: