What is Exception handling?
In [[computing]], an '''exception''' is a special situation where the [[Computer program|program]] cannot do things the way it usually would and is forced to do something else instead. One layer of the system uses an exception to give another layer information about special states the system is currently in. The different layers of software or hardware have contracts, that tell what can be expected; this is generally known as [[Programming by Contract]]. In the context of exception handling, a program is said to be exception-safe, if exceptions that occur will not produce side-effects (such as [[memory leak]]s), will not change stored data so that it becomes unreadable, or generate output that is invalid. There are different levels of exception safety: #'''Failure transparency''' or '''no throw guarantee''': No matter what happens, no exceptions will be thrown. This is the best level of exception safety, but also the most difficult to implement. #'''Commit or rollback semantics''', '''Strong exception safety''', '''no change guarantee''': Operations can fail, and exceptions will be thrown. However, a failed operation is guaranteed to not have side-effects or change the data.<ref>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1997/N1077.asc</ref> #'''Basic exception safety''': A part of the failed operation may have been executed, and can have side-effects. The state of the data may be different before and after the execution, but in both cases, the data will be in a valid state. #'''Minimal exception safety''','''No-leak guarantee''': As only a part of the operation was executed, the stored data may be invalid, afterwards. The system will keep running, and no resources get leaked, however. #'''No exception safety''': No guarantees can be made. This is the worst level of exception safety. Usually, a programmer will try to ''catch'' the exception early so that problems don't get worse over time. == Example == Suppose a program tries to add something to an ''array'', or group of ''[[object]]s'' that doesn't ex