Summary
The traditional way of informing a program about unexpected events is using an error return code from the function that detected the event. This way is fraught with risk because developers do not always remember to check return codes. Exceptions overcome this risk because an exception is either caught or it terminates the program.
The features of C++ exception handling are designed to process unexpected events during program execution.
A thrown exception unwinds the stack, calling the destructor of each variable in each scope as it is unwound. Using the RAII idiom, classes that own resources (such as dynamic variables, open file handles, mutexes, and so on) can release these resources. Because resources are released as the stack is unwound, it is safe to continue program execution after catching an exception.
A try/catch
block can catch exceptions. The catch
clauses can choose either to continue or halt program execution.
This is the end of the book, The C++ Workshop...